diff --git a/.claude/audits/BUGS-FOUND.md b/.claude/audits/BUGS-FOUND.md new file mode 100644 index 00000000..154c98ca --- /dev/null +++ b/.claude/audits/BUGS-FOUND.md @@ -0,0 +1,15 @@ +# BUGS-FOUND — behavior-changing findings quarantined by audits + +Findings that fixing would change observable behavior — logged here by +audit/cleanup passes, never fixed by them. Route to /bugfix or /feat. + +## Tour 2026-07-12 (clean-phase audit) — ALL FIXED 2026-07-12 (user-directed pass, same branch) + +| id | file:line | description | severity | +|----|-----------|-------------|----------| +| B-1 (fixed 83f02c8) | src/components/ui/Dialog.tsx:54 | Close button `aria-label="Fermer"` hardcoded French — every dialog exposes a French label to EN-locale screen-reader users. No `common.close` key exists; fix = add key to both dicts + `t()` | low (a11y/i18n) | +| B-2 (fixed 83f02c8) | src/components/brand/LanguageSwitcher.tsx | Group `aria-label="Language"` hardcoded English — FR users get English group label. Fix = new dict key | low (a11y/i18n) | +| B-3 (fixed f58a49f) | src/state/reportStore.ts:145-152 | Draft persistence write-only: every change mirrors report to sessionStorage `osteo:draft`, but no code path restores it — refresh loses session despite the mirror. `readPersistedDraft()` (reportStore.ts:154) exists unused; either implement restore or remove mirror+helper. CLAUDE.md advertises the auto-save | medium (unfinished feature) | +| B-4 (fixed 255ab96) | src/i18n/fr.ts vs en.ts (`pdf.title_prefix`) | PDF title prefix semantics differ per locale: FR 'Bilan ostéo — ' vs EN 'Faunosteo — ' (document type vs brand). Possibly unintended discrepancy in exported PDF metadata | low | +| B-5 (fixed 74e1623) | src/app/routes/SvgEditorRoute.tsx:146,152,154 | Hardcoded placeholders `"head"`, `"ex: Hanche"`, `"ex: Hip joint"` bypass i18n on an otherwise localized page. Possibly intentional examples | low | +| B-6 (fixed b047d35) | src/domain/species/types.ts:19 + AnimalForm.tsx:32 | SpeciesManifest only carries `labelFr` — species dropdown shows "Cheval" to EN users. Fix requires manifest type change (labelEn) | low (i18n gap) | diff --git a/.claude/audits/TOUR.md b/.claude/audits/TOUR.md new file mode 100644 index 00000000..25cce27f --- /dev/null +++ b/.claude/audits/TOUR.md @@ -0,0 +1,43 @@ +# TOUR — grouped multi-axis sweep reports (append-only) + +## Tour 2026-07-12 — branch chore/tour-2026-07-12 — 3 iterations — CONVERGED + +Axes: security (semgrep floor ×3 + cso posture it1) · clean · reconcile (report-only) · doc. +Iteration 2 clean pass was delta-scoped (3 doc files — only changes since it1's full audit + PASS re-verify). +Iteration 3 ran because it2 surfaced 1 new tuning note; it3 = fresh semgrep on unchanged tree → identical result, 0 new → converged. + +| ID | Axis | File | Sev | Finding | Status | +|----|------|------|-----|---------|--------| +| SEC-1 | security | package.json | crit/high | CVE deps: vite (GHSA-fx2h-pf6j-xcff HIGH), vitest (GHSA-5xrq-8626-4rwp CRIT dev), happy-dom (GHSA-37j7-fg3j-429f CRIT dev), esbuild, js-yaml | fixed 18865de — pnpm audit: 0 vulns | +| SEC-2 | security | SvgEditorRoute.tsx:498, pathology-editor.html:1126 | medium | user-dropped SVGs inserted without full sanitization (React editor: none; HTML editor: missed root on* + javascript: hrefs) | fixed 3f91a45 | +| SEC-3 | security | package.json | low | build toolchain (vite + plugins) in prod dependencies — inflated audit surface | fixed 187dfb5 | +| SEC-4 | security | Dockerfile:34 | high | semgrep BLOCK: no USER before ENTRYPOINT — container ran as root | fixed d8e478a — **BREAKING**: PORT env must now be >=1024 (default 8080 unaffected). Docker-verified: build, HTTP 200, SPA fallback, env override, ps = uid 101 | +| SEC-5 | security | .npmrc | medium | no minimum-release-age supply-chain guard | fixed a2bd884 (1440 min) | +| SEC-6 | security | Dockerfile:19 | low | unpinned nginx:alpine base | fixed c55da07 (nginx:1.31-alpine, build-verified) | +| SEC-7 | security | docker/nginx.conf:10,16,21 | medium | add_header inside location blocks — silently drops server-level headers if any are added later | open — defer to /harden (no server-level headers exist yet) | +| SEC-8 | security | src/pdf/attachment.ts:64-72 | low | no decompression-bomb cap on PDF import inflate | open — protected path (CLAUDE.md: ask before changing import) | +| SEC-9 | security | docker/entrypoint.sh:10-17 | low | unescaped env interpolation in env.js heredoc (operator-controlled input; a quote in APP_* breaks the JS) | open | +| SEC-10 | security | .npmrc | low | minimum-release-age=1440 below semgrep-recommended 10080 | open — deliberate 24h dev-velocity trade-off; human call | +| CLN-1 | clean | src (6 sites) | - | dead code: assertNever, canvg dep (never imported), VertebraPicker re-export shim, equine named export, validateBoneElement export, rasterizeSvg _scale param | fixed bbdc0e8 (−93 lines net) | +| CLN-2 | clean | pdf/render, EditorRoute, svgConvention | - | byte-identical word-wrap ×2 → pdf/render/text.ts; mergeBones block ×2 → helper; getBoneIdFromEvent dup walk-up → delegates | fixed bbdc0e8 | +| CLN-3 | clean | i18n/{fr,en}.ts, LanguageSwitcher | - | 6 dead dict keys; switcher hardcoded strings identical to existing lang.* keys | fixed 4ea8c90 (parity 204/204) | +| CLN-4 | clean | Brand.tsx:7 | - | hardcoded alt="Faunosteo" — identity rule violation | fixed 86ac366 (alt via useConfig) | +| CLN-5 | clean | reportStore.ts:154 | - | readPersistedDraft() never called — entangled with bug B-3 (write-only draft mirror); deleting would prejudge the product fix | open — see BUGS-FOUND.md B-3 | +| CLN-6 | clean | anatomy/types.ts:43 + styles/index.css:13 | - | BoneState 'linked'/'multi' never produced + 2 dead CSS rules — possible planned feature | open — human call | +| CLN-7 | clean | public/assets (22 of 24 PNGs) | - | unused logo sizes ship in every build/Docker image | open — confirm no external hotlinks before deleting | +| CLN-8 | clean | labels/canvas/pdf/EditorRoute | - | larger refactors: locale-fallback dedup (6+ sites), PDF constants module, onZoneClick ~60 logic lines, addObservationPage ~200 lines/9 params | open — beyond tour minimal-fix scope, route to /refactor | +| CLN-9 | clean | pdf/attachment.ts:23 | - | attachment description hardcodes brand ('Faunosteo state v2') — PDF format contract | open — confirm before touching (docs/PDF-FORMAT.md) | +| CLN-10 | clean | Dialog/LanguageSwitcher/reportStore/i18n/SvgEditorRoute/species types | - | 6 behavior-changing findings (hardcoded aria labels FR/EN, write-only draft, PDF title prefix asymmetry, i18n placeholders, labelFr-only species) | quarantined → BUGS-FOUND.md B-1..B-6, code untouched | +| REC-1 | reconcile | .claude/tasks/TODO.md:147-149 | - | declared cross-refs "BDR-001..008, LRN-001..010, BLK-001..004" \| real: 22 BDR / 29 LRN / 5 BLK | suggested — update ranges via /reconcile | +| REC-2 | reconcile | TODO.md:126 | - | declared "[ ] env-var brand identity verified" \| real: verified this tour (docker run APP_BRAND_NAME=TourCheck → env.js correct, non-root) | suggested — check box with evidence | +| REC-3 | reconcile | TODO.md:50 | - | declared "[x] sessionStorage draft mirror" \| real: mirror write-only, no restore path (B-3) | suggested — add open item "draft restore or drop mirror" | +| REC-4 | reconcile | CLAUDE.md | - | declared: canvg raster, svgToPngDataUrl(), ReportSchema.version=1, pako, pnpm at ~/.local/share/pnpm/bin \| real: native raster, rasterizeSvg, version 2, DecompressionStream, pnpm at ~/.local/bin | suggested — human-applied CLAUDE.md sync (tour never edits it) | +| DOC-1 | doc | README.md | - | canvg credited for PDF rasterization (feature bullet + stack list) | fixed 1078f74 | +| DOC-2 | doc | DEPLOY.md | - | stale: generic nginx:alpine, root container, no PORT constraint, `origin/master` reference (remote only has main/develop) | fixed 1078f74 | +| DOC-3 | doc | CHANGELOG.md | - | Unreleased section missing tour changes (canvg removal, base pin, security fixes) | fixed 1078f74 | + +Checks: typecheck PASS · eslint PASS (0 warnings) · vitest 174/174 PASS · vite build PASS · docker build+run PASS (non-root verified). +Residuals: SEC-7..10, CLN-5..9 (all `open` above) + info: vite chunk >500 kB warning (pre-existing); CI build/push/deploy still unverified (TODO.md:130). +Iteration 2 cso pass skipped by design (iteration-1-only posture audit). semgrep floor ran every iteration (it1 BLOCK(1) → it2 PASS → it3 PASS identical). +Commits: 11 (6 security, 3 clean, 1 doc, 1 report). BREAKING: 1 (SEC-4 — PORT >=1024). +Branch chore/tour-2026-07-12 left UNMERGED — review, then `gitflow finish` on your GO. diff --git a/.claude/memory/evals.md b/.claude/memory/evals.md index aacd3e0c..b162c166 100644 --- a/.claude/memory/evals.md +++ b/.claude/memory/evals.md @@ -28,3 +28,10 @@ Method: user manual export of a v2.0 horse report containing requires_vet_referr Result: 154/154 tests stayed green; bug shipped to user-facing path. Static signal absent (the ⚠ literal was visible in the source but typecheck/lint don't flag font-encoding issues). Anomaly: pdf.roundtrip.test.ts exercised export with empty observations + no vet findings. The ⚠ prefix was added in 60e1b04-era (`observationPage.ts:407` ternary) without a regression case covering a flagged leaf. Action: hotfix swapped ⚠ → `(!) ` (WinAnsi-safe). Added regression `vet-referral marker is encodable by the body font` that calls `widthOfTextAtSize` on a prefixed label — would catch any future non-WinAnsi marker. LRN-021 captured the pdf-lib StandardFonts WinAnsi limitation. Follow-up: switch PDF body to embedded TTF (Inter/Fraunces per CLAUDE.md spec) so the catalog can carry arbitrary glyphs — out of hotfix scope. + +## EVAL-004 | 2026-07-12 | Tour sweep converged 3 it. — agent spend-limit deaths resumable + +Method: /tour full pipeline on faunosteo — semgrep floor ×3 + cso posture (it1) + full clean audit + fresh independent re-verify + doc-syncer. 13 fixed / 10 open residuals / 6 bugs quarantined; 11 commits on unmerged chore/tour-2026-07-12. +Result: re-verify PASS (0 findings on 20 modified files); checks green throughout (typecheck, lint 0, 174/174, build, docker run non-root). Convergence honest: it2 surfaced 1 new tuning note (min-release-age 1440 < 10080 rec) → triaged open → it3 semgrep identical → converged at 3-iteration bound. +Anomaly: both Phase A agents died mid-run on "monthly spend limit" — SendMessage to same agentId resumed from transcript, zero rework. PostToolUse hook false-positived 3× on 'dangerouslySetInnerHTML' as prose inside audit REPORTS (not code). +Action: none blocking. Consider excluding .claude/audits/*.md from sink-pattern hook scan. diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index fe871db1..d7fc4f92 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -159,3 +159,9 @@ feat(ui+pdf): footer partnership credit "Paws iin Harmony" text -> Paws_in_harmo fix(editor) 2803cf7 — pathology-editor.html 404 in prod (faunosteo.com/pathology-editor.html). Root cause: file at repo root, Vite bundles only index.html -> never in dist/ -> nginx SPA-fallback -> React "Page introuvable". Worked in `pnpm dev` (serves root files), hid prod gap. Fix: git mv -> public/ (copied verbatim to dist/), href unchanged (public/=web root). Verified via vite preview: /pathology-editor.html=200 text/html. CLAUDE.md + README folder maps synced. LRN-029 captured. Pushed 97f8a92. - Decided NOT to unify pathology-editor with svg-editor React-route pattern. BDR-022: asymmetry intentional (svg reuses app internals, pathology isolated zero-imports + produces prod JSON -> minimal-change zone). Verified editor fetches same prod assets as app (/species/equine/{pathologies.json,Horse.svg,Horse_head.svg}, all in dist/). No code change. + +--- + +## 2026-07-12 + +/tour full sweep — branch chore/tour-2026-07-12, 11 commits, UNMERGED (human review pending). Security: CVE deps patched (pnpm audit 0), SVG import sanitized both editors, container non-root (BREAKING: PORT >=1024), nginx:1.31-alpine pin, min-release-age guard. Clean: -93 lines dead code (canvg dep dropped), 3 dedup extracts, i18n dead keys purged. Docs synced (README/DEPLOY/CHANGELOG, incl. stale origin/master). 6 bugs quarantined -> BUGS-FOUND.md (worst: B-3 draft mirror write-only). 4 reconcile suggestions pending /reconcile. Report: .claude/audits/TOUR.md. LRN-030/031, EVAL-004 captured. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index 0772c59e..acd35f84 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -232,3 +232,15 @@ Apply: any feature where "select X in modal → reflect in N places". Find the s Extra .html at repo root never reaches dist/ — Vite build entry = index.html only. Prod 404: nginx try_files falls through to SPA index.html, React shows "Page introuvable". Fix: put standalone HTML in public/ (copied verbatim to dist/). Links resolve from web root, so href stays /file.html. **Why:** pathology-editor.html shipped at root (BDR-020 standalone-HTML pattern), worked in `pnpm dev` (Vite serves root files in dev) but 404'd in prod (only public/ + bundled entries land in dist/). Dev-vs-prod gap hid it. **How to apply:** standalone HTML tool / extra entry → public/, OR add to vite build.rollupOptions.input for hashed-asset processing. Verify via `vite preview` (serves real dist/), not just `pnpm dev`. Ties to [[BDR-020]]. + +## LRN-030 | 2026-07-12 | Dockerized SPA on port >=1024 — full non-root nginx works + +nginx:alpine default = master root, workers nginx. Listen port >=1024 → USER nginx viable: chown /var/cache/nginx + pre-created /var/run/nginx.pid + /etc/nginx/conf.d (entrypoint envsubst rewrite) + html dir (env.js write). Official image log symlinks (/dev/stdout|stderr) work non-root. +**Why:** tour 2026-07-12 semgrep HIGH (no USER before ENTRYPOINT, Dockerfile:34). Fixed d8e478a; verified docker run: HTTP 200, SPA fallback, env override, ps = uid 101 master+workers. +**How to apply:** any nginx-served SPA container: keep listen >=1024, chown the 4 paths above, USER nginx. Contract change: PORT <1024 now fails to bind — flag BREAKING. Alt base: nginxinc/nginx-unprivileged. + +## LRN-031 | 2026-07-12 | Build toolchain in dependencies inflates prod CVE audit surface + +vite + @vitejs/plugin-react-swc + @tailwindcss/vite sat in dependencies → `pnpm audit --prod` reported their CVEs as prod findings. Build-time-only packages belong in devDependencies; SPA runtime imports none of them. +**Why:** tour 2026-07-12 cso posture audit — all 3 "prod" advisories were build-toolchain. Moved 187dfb5; build+tests green, prod audit clean. +**How to apply:** scaffold check: anything imported only by vite.config / build pipeline → devDependencies. Then `pnpm audit --prod` reflects real runtime surface. Docker multi-stage unaffected (builder installs all). diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 8af7c37c..517aa2ea 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -38,6 +38,10 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo - [x] pathology-editor.html prod 404 fixed — served from public/ so it ships to dist (2803cf7, LRN-029) - [x] gitflow socle + pre-commit hook adopted (4991c10) +### Tour + fixes 2026-07-12 (branch chore/tour-2026-07-12 — UNMERGED, review pending) +- [x] /tour sweep: CVE deps patched (pnpm audit 0), SVG import sanitized, container non-root (**BREAKING: PORT >=1024**), nginx:1.31-alpine pin, dead code −93 lines (canvg dropped), docs synced. Report: .claude/audits/TOUR.md +- [x] Post-tour fixes: aria-labels i18n (B-1/B-2), EN PDF title prefix (B-4), SvgEditor placeholders (B-5), species labelEn (B-6), draft restore (B-3, TDD), entrypoint escaping (SEC-9), PDF decompression cap (SEC-8, TDD), dead BoneState + 22 unused PNGs (CLN-6/7). 180/180 tests. + --- ## Phase A — DONE (kept for reference) @@ -47,7 +51,7 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo - [x] Anatomy: parseSvgBones, loadSvg, svgToPng raster - [x] Zustand store: full action set (initReport, hydrateReport, observation CRUD, conclusion/recommendations/nextAppointment setters, identity setters) -- [x] sessionStorage draft mirror + localStorage practitioner cache +- [x] sessionStorage draft mirror + localStorage practitioner cache (restore path was missing until f58a49f 2026-07-12 — refresh now keeps the session) - [x] UI primitives: Button, Card, Dialog, Input, Label, Select, Textarea, Badge, Chip - [x] Canvas: AnatomyCanvas (data-state highlighting, async-mount safe), DetailModal - [x] Observation chain: ObservationList, ObservationCard, PathologyPicker (flat — REMOVED, replaced by FindingsTreePicker B2), @@ -123,7 +127,7 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo - [ ] PDF QA manual pass: full flow → export → re-import roundtrip - Fonts embed, JSON attached, multi-SVG grid OK, locale FR + EN exports - [x] Docker build + compose up smoke test (VPS cold build validated — BLK-005, 990c8e7; local smoke not separately logged) -- [ ] env-var brand identity verified +- [x] env-var brand identity verified (tour 2026-07-12: docker run APP_BRAND_NAME=TourCheck → env.js correct, non-root; hostile-quotes case covered by 0214ae1) - [x] README finalize (install, dev, Docker, env vars, locale, MIT) - [x] CHANGELOG 0.1.0 entry - [x] docs/PATHOLOGIES-FORMAT.md — schema doc + authoring guide (initial shipped 70f21cc 2026-05-20; refreshed for v2.0 boolean-only contract 2026-05-21 — scope section, 5 taxonomy patterns, structural rules, breaking-change notice, horse stats, changelog v1.0→v2.0) @@ -144,9 +148,9 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo ## Memory cross-refs -- BDR-001..BDR-008 — decisions registry -- LRN-001..LRN-010 — learnings registry -- BLK-001..BLK-004 — blockers (all resolved) +- BDR-001..BDR-022 — decisions registry +- LRN-001..LRN-031 — learnings registry +- BLK-001..BLK-005 — blockers (all resolved) Apply when implementing B-phase: - LRN-004 (data-anno-special opaque to parser) — zone IDs in JSON must match SVG `data-anno-id` diff --git a/.npmrc b/.npmrc index 3e6c04e8..630ea829 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,4 @@ shamefully-hoist=false strict-peer-dependencies=false +# Supply-chain guard: only install package versions published >= 24h ago +minimum-release-age=1440 diff --git a/CHANGELOG.md b/CHANGELOG.md index c1dec3db..6236a7d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,10 +21,21 @@ Versions follow [Semantic Versioning](https://semver.org/). - **Responsive mobile** — full phone/tablet adaptation across all components. - **Project renamed** Zoosteo → Faunosteo across the whole codebase. +### Removed + +- **`canvg` dependency** — PDF SVG rasterization now uses the browser's native `Image`/`canvas` pipeline (`src/pdf/render/svgToPng.ts`) instead of the `canvg` library. + ### Fixed - **`pathology-editor.html` 404 in production** — it lived at the repo root, Vite never bundled it into `dist/`; moved to `public/` so it ships (LRN-029). - **Docker species caching** — `Cache-Control: no-cache` header added for `/species/` assets so an updated catalog is served fresh. +- **nginx runner base image** pinned to `nginx:1.31-alpine` (was the floating `nginx:alpine` tag). + +### Security + +- **Docker container runs fully as non-root** (`USER nginx`) — `PORT` must now be `>=1024` (default `8080` unaffected). +- **Supply-chain guard** — `.npmrc` gained `minimum-release-age=1440`, blocking install of package versions published less than 24h ago. +- **User-imported SVGs sanitized** — the SVG editor and the standalone pathology editor now strip `