You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[problems-core] Validate Problem extensions before they can corrupt serialization #2006
Problem extensions are assigned after RFC 7807 core fields and are only shallowly validated. Reserved keys can overwrite status, code, or title, while cyclic values, BigInt, functions, and hostile getters can make serialization throw and mask the original failure.
Evidence
Source of truth: origin/trunk@678073d994294db7e21b5a4d0a004a087ea498e0.
packages/problems-core/src/libs/Problem.ts:90-108 applies Object.assign(result, this.extensions) after setting core fields.
packages/problems-core/src/libs/validateExtensions.ts:10-24 accepts any non-null object without recursive JSON-safety or cycle validation.
Desired outcome
Problem core fields remain authoritative and every accepted extension is deterministically JSON-safe.
Proposed implementation
Reject reserved RFC 7807 and Croco core keys at Problem construction.
Recursively validate plain JSON data with cycle detection and bounded diagnostics.
Copy only validated extension fields into serialized output.
Acceptance criteria
Extensions cannot override type, title, status, detail, instance, or code.
Cycles, BigInt, symbol/function values, non-plain containers, and throwing property access fail with a stable Problem.
Nested JSON-safe records and arrays retain round-trip behavior.
Serialization never replaces the original Problem with an unrelated runtime error.
Validation
pnpm --dir packages/problems-core vitest run src/tests/Problem.spec.ts src/tests/ProblemSerializer.spec.ts
pnpm --filter @croco/problems-core typecheck
Scope boundaries
Do not add fallback serialization for arbitrary class instances.
Activity