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

+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__')
})
})