Skip to content

[problems-core] Validate Problem extensions before they can corrupt serialization #2006

Closed

Description

@kang-heewon

Priority

P1

Problem

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

  1. Reject reserved RFC 7807 and Croco core keys at Problem construction.
  2. Recursively validate plain JSON data with cycle detection and bounded diagnostics.
  3. 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

  1. added
    bugSomething isn't working
    error-handlingError handling and failure semantics
    P1Priority 1 issue
    api-contractAPI, RPC, route, and schema contract work
    on Aug 23, 2026
  2. self-assigned this
    on Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1Priority 1 issueapi-contractAPI, RPC, route, and schema contract workbugSomething isn't workingerror-handlingError handling and failure semanticsproblems-core

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions