Repository navigation
Description
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
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
-
Add
objectFields: 1000toLIMITSinvalidate-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, }); -
Track object field cardinality in
enforceJsonTextLimits:
Count object fields on transition to key/colon states, raisingJsonStructureError("input exceeds 1000 field object limit")beforeJSON.parseis ever called. -
Check
keys.lengthincollectDataLimitErrors:} else { const keys = Object.keys(current.value); + if (keys.length > LIMITS.objectFields) { + return [escapeUnsafeDiagnosticCharacters(`${current.location}: exceeds ${LIMITS.objectFields} field object limit`)]; + } -
Add early exit in property validation loop:
Break out offor (const key of Object.keys(value))whenerrors.length >= LIMITS.validationErrors. -
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
MohitRawat017 commentedon Oct 25, 2026
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.
Inkesk-Dozing commentedon Oct 25, 2026
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.
Enforce the 1,000-field object limit in validate-findings.cjs