fix(domain,app): own-key lookups for untrusted ids in the v2 migration, attachment and PDF size caps; EVAL-011, journal, TODO

This commit is contained in:
bchanot committed 2026-10-10 12:23:03 +02:00
1 parent 17a6d9b323
commit e7f4167ada
8 files changed
+76 -5

No files matched your search

+9
View File
@@ -80,3 +80,12 @@ Method: 4 research agents (skull, axial, limbs, osteo/legal), every citation tag
Result: verifier pass 1 ECARTS(4): B changes left targets `inherited` (CHG-008/032/039 + partials), 3 stale doc numbers, lockfile outside contract scope (orchestrator omission), eslint-disable any in a test → executor: applier rule (B/C ⇒ touched findings/annotations `to_confirm`, `reviewed` refused in B/C), typed test reads, docs. Pass 2 ECARTS(2): JSAVA citation without author (completed from the PDF: Le Roux & Carstens 2018, DOI), DEPLOY.md stale `faunosteo-web`. Pass 3 ECARTS(1): 3 stale doc lines (migration list, "two assets", CLAUDE.md migrations) → fixed by hand, cap of 3 verifier passes reached, not re-verified. Security PASS, LOW: SQL gate did not check reference url scheme → `reference.url.scheme` added (migration still unmerged, pgTAP 008 10 cases); `.env.example` COMPOSE_PROJECT_NAME=osteo-report overrides compose `name:` → file denied to Claude, user action.
Anomalies: ImageMagick MSVG drops `fill="none"` shapes and shapes with `<title>` child (LRN-042); two legacy points (t18-l1, l6-s1) floated above the silhouette, found only by the overlay render, not by the catalog audit; Supabase `db reset` unconfirms the asset row (upload script must re-run: objects kept, row confirmed).
Action: user validation of the draft content (REVIEW-REPORT §10: 11 questions); never publish; Step 5 only after validation.
---
## EVAL-011 | 2026-10-10 | Step 5 app on the canonical sheet — suites on the bundled sheet, archive PDFs, gates
Method: golden v2 PDFs frozen from the old pipeline before any change; suites rewritten on the bundled draft (domain 94, anatomy 107, supabase 21, app 168+: service branches 10/5/12/1, store + v2 draft migration, provider, canvas, pickers, card, route click chain, PDF v3 roundtrip FR/EN + both v2 fixtures + synthetic removed/unknown ids); root check, vite builds none/draft (grep of a draft label in dist = 0/1), docker build, real stack 267/267 + types; legacy-vs-app marker style diff by the verifier (0 differences); fresh verifier ×3 + security-auditor ×1.
Result: verifier pass 1 ECARTS(36) = 4 real (golden test not pinning the new generated files, EditorRoute 398 lines, 5 stale doc lines, one eslint-disable) + my contract omissions (scope files, deleted legacy suites) + floor noise ("species" matched "spec"); pass 2 ECARTS(4) = replacement assertions missing for 4 deleted suites; pass 3 ECARTS(4) = doc counts + 3 more suites' assertions (PDF conclusion/metadata/attachment structure, ObservationCard, persistence). All closed by executors (two) and by hand (docs); cap of 3 passes reached → last lot not re-verified. Security PASS with LOW: prototype-key lookup on untrusted ids (fixed: Object.hasOwn + test), unbounded inflate on the primary attachment path + no file cap (fixed: 16 MiB attachment, 50 MB PDF + test), denylist SVG sanitiser acceptable while assets are repo-built (allowlist before Storage-served assets, Step 13).
Anomalies: executor ran `pnpm format` repo-wide and reverted by hand (watch for `format` in briefs); foreign JSON attachment (no version) surfaced as incompatible_version → fixed to no_attachment (legacy message); verifier floor counts deleted legacy tests as findings until CLARIFICATIONS name them.
Action: user validation of Step 5 (manual FR/EN flow, visual before/after); BDR-038, LRN-043.
+1
View File
@@ -191,3 +191,4 @@ Step 4 validated + finished into develop. User decisions on the 7 open points
- Step 4c VALIDATED by user 2026-10-10 → tracking: head view check documented (spec §6), BLK-008 migration limit, BDR-037, DEPLOY.md `.env.example` note. Finished into develop. Next: Step 5 (app on the canonical sheet), design points flagged before any UI work.
- Step 5 preparation (2026-10-10): 4 analyzer agents (core/store, rendering, PDF, tests) + plan/spec reading → docs/development/STEP5_MIGRATION_ANALYSIS.md on chore/step-05-migration-analysis. Key facts: all 27 legacy data-anno-ids differ from canonical ids; 170/612 legacy finding paths moved/removed by curation → generated report-migration-map; markers never drawn by the app (in the SVG); PDF depends on markers only for the highlight; 66 tests import the registry. 8 decisions D1–D8 await the user. No implementation.
- Step 5 implemented (2026-10-10, feature/step-05-app-on-canonical-sheet): domain report v3 + migration (80 tests), pipeline migration map/sheet-ref/app review drawings + layer renderer (110), app rewritten on the sheet (99 tests: service, store, provider, canvas, pickers, PDF v2/v3, route), legacy code removed, docs rewritten (ANNOTATION-RENDERING.md replaces the SVG convention). Root check green, docker build OK, real stack 267/267, default build carries no sheet. BDR-038, LRN-043. Gates next; awaiting user validation.
- Step 5 gates (2026-10-10): verifier 36→4→4 (real gaps closed by 2 executors + doc fixes; cap reached, last test lot unverified by a 4th pass), security PASS (2 LOW fixed: prototype keys, size caps). EVAL-011. Final check green. Awaiting user validation; no publication; default build carries no sheet.
+2 -1
View File
@@ -94,7 +94,8 @@ feat/findings-tree-v2 merged (FindingsTreePicker tracked in HEAD); all work belo
- [x] 5.4 zoneInteraction service + reducers, store split + sessionStoragePersistence (v2 migration on load), pickers/cards on sheetIndex (D6 ranges, D7 title), EditorRoute < 300 lines
- [x] 5.5 PDF shim + attachment v3 + v2 import (gate D3)
- [x] 5.6 delete legacy (registry, species/*, zoneMatch, spineZones, svgConvention, D4 tools), SVG convention doc replaced, CLAUDE.md map, CHANGELOG, plan note, memory
- [~] 5.7 visual before/after done (cmp renders), root check + docker + real stack green; gates verifier + security pending; manual FR/EN flow = user validation
- [x] 5.7 visual before/after (cmp renders), root check + docker + real stack green; verifier ×3 (gaps closed), security PASS (LOW fixed); EVAL-011. Manual FR/EN flow = user validation
- [ ] 5 follow-up: allowlist SVG sanitiser before Storage-served assets (Step 13); orphan findings UX (D5) at the report UX step; per-leaf adapter test over the 612 legacy leaves (map-level coverage today)
---
+7 -1
View File
@@ -65,10 +65,16 @@ export async function extractReportJson(
return parseAttachment(fallback, map)
}
/** Hard ceiling on an attachment (inflated or not): a report is a few hundred KB at most. */
const MAX_ATTACHMENT_BYTES = 16 * 1024 * 1024
function parseAttachment(
bytes: Uint8Array,
map: ReportMigrationMap,
): ExtractedReport {
if (bytes.byteLength > MAX_ATTACHMENT_BYTES) {
throw new Error('attachment too large')
}
const data: unknown = JSON.parse(new TextDecoder().decode(bytes))
const version =
data !== null &&
@@ -100,7 +106,7 @@ interface RawObj {
* Hard ceiling on inflated attachment size. A valid report JSON is far
* smaller; anything bigger is a decompression bomb or corruption.
*/
const MAX_INFLATED_BYTES = 16 * 1024 * 1024
const MAX_INFLATED_BYTES = MAX_ATTACHMENT_BYTES
/** Exported for tests. Returns null on failure or when the cap is exceeded. */
export async function inflateFlate(
+4
View File
@@ -31,10 +31,14 @@ export class ImportError extends Error {
* through the reference sheet's map). The outcome says whether a migration
* happened and how many zones or findings it could not place.
*/
/** A Faunosteo PDF weighs a few hundred KB; anything larger is not one. */
export const MAX_PDF_BYTES = 50 * 1024 * 1024
export async function importReportFromPdf(
pdfBytes: Uint8Array,
map: ReportMigrationMap,
): Promise<ExtractedReport> {
if (pdfBytes.byteLength > MAX_PDF_BYTES) throw new ImportError('invalid_pdf')
let pdfDoc: PDFDocument
try {
pdfDoc = await PDFDocument.load(pdfBytes, { ignoreEncryption: true })
@@ -37,3 +37,14 @@ describe('PDF attachment roundtrip', () => {
).rejects.toThrow()
})
})
describe('size caps', () => {
it('refuses an oversized PDF before parsing it', async () => {
const { importReportFromPdf, ImportError, MAX_PDF_BYTES } =
await import('@/pdf/import')
const huge = new Uint8Array(MAX_PDF_BYTES + 1)
await expect(
importReportFromPdf(huge, sheet.sheet.migrationMap),
).rejects.toBeInstanceOf(ImportError)
})
})
+11 -3
View File
@@ -25,6 +25,11 @@ import {
* data survives any catalog change and stays identifiable.
*/
/** Own-key lookup: ids come from untrusted documents (`__proto__` is not an entry). */
function own<T>(record: Record<string, T>, key: string): T | undefined {
return Object.hasOwn(record, key) ? record[key] : undefined
}
const SEVERITY: Record<SeverityV2, Severity> = {
légère: 'mild',
modérée: 'moderate',
@@ -43,9 +48,9 @@ function migrateZone(
zone: ObservationZoneV2,
map: ReportMigrationMap,
): ReportZone {
const entry = map.annotations[zone.boneId]
const entry = own(map.annotations, zone.boneId)
const viewId = zone.detailSourceId
? (map.views[zone.detailSourceId] ?? zone.detailSourceId)
? (own(map.views, zone.detailSourceId) ?? zone.detailSourceId)
: map.main_view_id
const out: ReportZone = { annotationId: entry?.id ?? zone.boneId, viewId }
if (zone.side) out.side = zone.side
@@ -60,7 +65,10 @@ function migrateZone(
}
function migrateFinding(finding: FindingV2, map: ReportMigrationMap): Finding {
const mapped = map.finding_paths[findingPathKey(finding.zoneId, finding.path)]
const mapped = own(
map.finding_paths,
findingPathKey(finding.zoneId, finding.path),
)
const out: Finding = {
findingZoneId: finding.zoneId,
path: [...finding.path],
@@ -224,3 +224,34 @@ describe('readReportDocument', () => {
}
})
})
describe('hostile identifiers', () => {
it('treats prototype keys as unknown ids instead of throwing', () => {
const odd = {
...ReportV2Schema.parse(minimal),
observations: [
{
id: 'o',
zones: [
{ boneId: '__proto__' },
{ boneId: 'constructor', detailSourceId: '__proto__' },
],
findings: [
{
zoneId: 'constructor',
path: ['__proto__'],
labelFrSnapshot: 'X',
labelEnSnapshot: 'X',
},
],
freeTextFindings: [],
comment: '',
},
],
}
const out = migrateReportV2ToV3(ReportV2Schema.parse(odd), MAP)
expect(out.unresolvedZones).toBe(2)
expect(out.unresolvedFindings).toBe(1)
expect(out.report.observations[0]!.zones[1]!.viewId).toBe('__proto__')
})
})