Skip to content

Asymmetric parser hardening: validate-findings.cjs lacks pre-parse and in-memory objectFields limits, exposing parent workflow to key-amplification DoS #107

Open

Description

@Inkesk-Dozing

Summary

In PR #12 ("Rework the audit workflow, findings contract, and validators end to end"), pre-parse text stream scanners and data limit invariants were introduced to defend the trusted parent process against hostile or amplified outputs produced by target-controlled code and subagents.

While validate-coverage-ledger.cjs strictly bounds object property cardinality both pre-parse (at token stream level) and post-parse (via LIMITS.objectFields = 1000), validate-findings.cjs omits object field cardinality bounding entirely. Within the allowed 5 MiB input limit, a findings payload with hundreds of thousands of keys bypasses pre-parse checks, forces full dictionary allocation in V8, and causes an unthrottled property iteration loop in validate().

This asymmetry results in a 163x latency disparity between the two sibling validators under identical payload scale.


Comparison of Defense-in-Depth Invariants

Invariant / Check validate-coverage-ledger.cjs validate-findings.cjs Status
Input byte bound LIMITS.inputBytes = 5 MiB LIMITS.inputBytes = 5 MiB Aligned
Nesting depth bound LIMITS.nestingDepth = 64 LIMITS.nestingDepth = 64 Aligned
Collection item bound LIMITS.collectionItems = 1000 LIMITS.arrayItems = 1000 Aligned
Object field bound LIMITS.objectFields = 1000 Missing / Not defined Vulnerable
Pre-parse field check Enforced in preflightJsonText() Omitted in enforceJsonTextLimits() Vulnerable
Post-parse data limit check Enforced in preflightDocument() Omitted in collectDataLimitErrors() Vulnerable
Shared alignment test validate-findings.test.cjs:L608 Requires parity across helpers Divergent

Pipeline Architecture Discrepancy

flowchart TD
    subgraph Coverage_Ledger_Pipeline ["validate-coverage-ledger.cjs (Hardened)"]
        A1[Raw Input 5 MiB] --> B1[preflightJsonText]
        B1 -->|Checks Depth, Array Items, AND Object Fields| C1{Field Count > 1000?}
        C1 -->|Yes| D1[Immediate Fail-Fast in ~3.9 ms\nZero JSON.parse allocation]
        C1 -->|No| E1[JSON.parse]
        E1 --> F1[preflightDocument verification]
        F1 --> G1[validateDocument checks]
    end

    subgraph Findings_Pipeline ["validate-findings.cjs (Current Gap)"]
        A2[Raw Input 5 MiB] --> B2[enforceJsonTextLimits]
        B2 -->|Checks ONLY Depth & Array Items| C2[Passes 150,000+ Keys Unchecked]
        C2 --> D2[JSON.parse: Allocates massive V8 Dictionary]
        D2 --> E2[collectDataLimitErrors: Ignores Object.keys length]
        E2 --> F2[validate: Loops over all 150,000 keys with Object.keys]
        F2 --> G2[High CPU & Memory Latency ~645 ms]
    end
Loading

Empirical Benchmark

Testing a 1.75 MB payload containing an object with 150,000 properties ({"k_0": 1, "k_1": 1, ...}) through both validator paths:

Payload size: 1.75 MiB (well within the 5 MiB input limit)

[validate-coverage-ledger.cjs]
Pre-parse check: preflightJsonText()
Result: Throws 'input exceeds 1000 field object limit'
Wall-clock elapsed: 3.95 ms
V8 Heap Impact: Minimal (scanned as raw string tokens)

[validate-findings.cjs]
Pre-parse check: enforceJsonTextLimits() -> PASSED (0 ms)
V8 JSON.parse: Forced allocation of 150,000 dictionary properties (~18 MiB heap)
Data limit check: collectDataLimitErrors() -> PASSED (unchecked)
Schema validation: validate()
Wall-clock elapsed: 645.61 ms
V8 Heap Impact: Heavy garbage collection overhead & string allocations

Under a full 5 MiB adversarial payload (~400,000 keys), validate-findings.cjs blocks the Node.js event loop synchronously for over 2.1 seconds.


Secondary Amplification in validate()

In validate-findings.cjs lines 399-405:

for (const key of Object.keys(value)) {
  if (hasOwn(schema.properties, key)) {
    validate(value[key], schema.properties[key], propertyPath(p, key), errors);
  } else if (hasOwn(schema, "additionalProperties") && schema.additionalProperties === false) {
    errors.push(`${p}: unexpected field ${safeQuote(key)}`);
  }
}

Even though createErrorList() caps diagnostic error messages at LIMITS.validationErrors (100 messages max), the for (const key of Object.keys(value)) loop does not break when errors.length >= LIMITS.validationErrors. It continues iterating over all 150,000 keys, evaluating string templates and calling safeQuote(key).


Proposed Resolution

  1. Add objectFields: 1000 to LIMITS in validate-findings.cjs:

     const LIMITS = Object.freeze({
       inputBytes: 5 * 1024 * 1024,
       nestingDepth: 64,
       arrayItems: 1000,
    +  objectFields: 1000,
       canonicalKeyBytes: 1024 * 1024,
       uniqueSetBytes: 5 * 1024 * 1024,
       validationErrors: 100,
     });
  2. Track object field cardinality in enforceJsonTextLimits:
    Count object fields on transition to key/colon states, raising JsonStructureError("input exceeds 1000 field object limit") before JSON.parse is ever called.

  3. Check keys.length in collectDataLimitErrors:

     } else {
       const keys = Object.keys(current.value);
    +  if (keys.length > LIMITS.objectFields) {
    +    return [escapeUnsafeDiagnosticCharacters(`${current.location}: exceeds ${LIMITS.objectFields} field object limit`)];
    +  }
  4. Add early exit in property validation loop:
    Break out of for (const key of Object.keys(value)) when errors.length >= LIMITS.validationErrors.

  5. Add corresponding tests to validate-findings.test.cjs:
    Verifying rejection of oversized objects both pre-parse (stream scanner) and post-parse.


I have prepared the reproduction script, regression tests, and patch. Happy to submit a PR if this approach aligns with the project's defense-in-depth model.

Activity

  1. MohitRawat017 commented on Oct 25, 2026

    @MohitRawat017

    Opened #111 implementing the resolution proposed here — full credit to @Inkesk-Dozing for the analysis; the implementation follows their proposed diff. If your own patch is already further along, say the word and I'll close mine in favor of it.

  2. Inkesk-Dozing commented on Oct 25, 2026

    @Inkesk-Dozing
    Author

    Hola @MohitRawat017. I am waiting for a maintainer to give the green light and assign me to it before I open my own PR. Until then, feel free to proceed with yours.

  3. added a commit that references this issue on Oct 26, 2026
    e7262ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions