T09 · Insecure Skill Coding Practices
- Location
SKILL.md:175- Finding
Unrestricted Custom Regular Expressions May Cause Denial of Service
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md:175andSKILL.md:236-241
Vulnerability Type: Regular Expression Denial of Service (ReDoS)
Risk Level: MediumVulnerable Code
python # Pattern check if 'pattern' in rule: if not re.match(rule['pattern'], str(value)): return ComplianceIssue( rule_id=rule['id'], rule_name=rule['name'], severity="error", message=f"Field '{field}' does not match required format", field=field, value=value )python def add_custom_rule(self, standard: Standard, rule: Dict): """Add custom compliance rule.""" if standard not in self.rules: self.rules[standard] = [] self.rules[standard].append(rule)Technical Analysis
The
add_custom_rulemethod accepts an unrestricted rule dictionary and stores it without schema validation, pattern validation, or length limits. If the rule contains apatternproperty,_check_rulepasses that pattern directly to Python's backtracking regular-expression engine throughre.match.Certain patterns, such as nested or ambiguous quantifiers, can exhibit catastrophic backtracking when evaluated against specially constructed long input. Neither the pattern execution nor the surrounding compliance check applies a timeout or computational complexity limit.
Exploitation requires an attacker or untrusted caller to be able to add a custom rule and subsequently cause validation of a crafted field value. The built-in patterns alone were not established as exploitable by this audit.
Attack Path
- An attacker supplies a custom rule containing a pathological expression, such as a nested-quantifier pattern.
- The application passes that rule to
add_custom_rule, which stores it without validation. - The attacker submits a long field value designed to force extensive regex backtracking.
- `c ...[truncated 629 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not accept arbitrary regular expressions from untrusted users. Prefer predefined validation operators or an allowlist of reviewed patterns.
- Define and enforce a strict schema for custom rules, including permitted keys, expected types, and maximum pattern and input lengths.
- Reject patterns containing dangerous constructs such as nested quantifiers, ambiguous alternations, or excessive repetition. Pattern inspection should be treated as defense in depth rather than a complete solution.
- Use a regular-expression engine with guaranteed linear-time behavior where available.
- If Python's
reengine must be used, perform untrusted matching in an isolated worker process with a strict execution timeout and resource limits so the worker can be terminated safely. - Limit the maximum size of values passed to regex validation.
- Restrict access to
add_custom_ruleto trusted administrators or trusted application code. - Add tests using known catastrophic-backtracking patterns and adversarially long input to verify that validation remains bounded.
