T09 · Insecure Skill Coding Practices
- Location
scripts/json_processor.py:123- Finding
Unbounded Regular Expression Evaluation Enables Denial of Service
- Content
View full analysis
Vulnerability Details
File Location:
scripts/json_processor.py, lines 123-125
Vulnerability Type: Regular expression denial of service through an untrusted schema pattern
Risk Level: MediumVulnerable Code:
python # pattern check (string) if "pattern" in schema_node and isinstance(value, str): if not re.search(schema_node["pattern"], value): errors.append(f"{path}: '{value}' does not match pattern {schema_node['pattern']}")Technical Analysis
The validator passes a pattern from a user-supplied JSON schema directly to Python's backtracking regular-expression engine. It also allows the subject string to originate from user-supplied JSON. No limits are imposed on pattern complexity, input length, or matching time.
A pattern with catastrophic backtracking, such as
(a+)+$, can require exponentially increasing CPU time when matched against a long near-matching string. Python's standardre.search()does not provide a timeout for this operation. An invalid pattern can also raise an uncaughtre.errorand terminate the command.Attack Path
- An attacker supplies or influences a schema consumed by the
validatecommand. - The schema defines a pathological expression in a
patternfield, such as(a+)+$. - The attacker supplies a corresponding JSON string containing many
acharacters followed by a nonmatching character. validate_schema()passes both values to unrestrictedre.search().- The regular-expression engine performs excessive backtracking, consuming CPU and delaying or preventing command completion. Alternatively, a malformed expression causes an uncaught exception.
Impact Assessment
Successful exploitation can exhaust CPU time or crash the JSON validation process. In an Agent or service that invokes this utility automatically, this could delay workflows, consume worker capacity, or cause repeated job failures.
The v ...[truncated 218 chars]
- An attacker supplies or influences a schema consumed by the
- Remediation
View remediation
Remediation Suggestions
- Treat schema patterns as untrusted input and enforce conservative maximum lengths for both patterns and subject strings.
- Reject unsupported or suspiciously complex constructs before evaluation.
- Catch
re.errorand report an ordinary schema-validation error rather than terminating the process. - When validation of untrusted patterns is required, use a regular-expression engine with guaranteed linear-time behavior or enforceable execution limits.
- Consider performing pattern matching in an isolated worker with strict CPU and wall-clock limits.
- Add regression tests using malformed patterns and known catastrophic-backtracking examples.
