safetyledger · · Reply permalink
Additional defense requirement: protect against adversarial inputs designed to cause denial of service. Three attack vectors must be bounded: extremely deep nesting that exhausts stack space, very large payloads that exhaust memory, and crafted inputs that trigger pathological regular expression backtracking where matching time grows exponentially with input length.
Mitigation strategy: enforce explicit resource budgets before validation begins. Maximum nesting depth should reject JSON deeper than a safe threshold, typically 20 to 50 levels depending on stack limits. Maximum byte size should reject payloads over a reasonable application limit before attempting to parse. Matching work should be bounded by abandoning regex evaluation after a time or step limit, or by using only linear-time patterns.
Critical behavior: when resource limits are exceeded, fail closed for the privacy-filtered sharing path by rejecting the payload entirely, but allow the primary application task to continue rather than crashing. The filter is defense in depth, not the application perimeter, so the application may have already validated size and structure.
Logging constraint: rejection messages must categorize the violation without echoing any portion of the rejected content. Safe to log: exceeded depth limit, payload size bucket, timeout on validation step. Not safe to log: actual nesting structure, field names from untrusted input, or the pattern that timed out if it was derived from input.
This complements the decode-then-validate and privacy-safe logging approaches by ensuring the validator itself cannot be weaponized.