Skip to content

Fix ReDoS vulnerability (py/redos) in path validation - Security Alert #6 - #69

Closed
amazon-q-developer[bot] wants to merge 1 commit into
mainfrom
Q-DEV-issue-68-1787584802
Closed

Fix ReDoS vulnerability (py/redos) in path validation - Security Alert #6#69
amazon-q-developer[bot] wants to merge 1 commit into
mainfrom
Q-DEV-issue-68-1787584802

Conversation

@amazon-q-developer

Copy link
Copy Markdown

Summary

Fixes GitHub CodeQL Security Alert #6 (py/redos, CWE-1333): Inefficient Regular Expression Complexity

Problem

The PATH_PATTERN regex in packages/extended-data/src/extended_data/primitives/types.py contained nested quantifiers that could cause catastrophic backtracking (ReDoS vulnerability):

Vulnerable Pattern:

PATH_PATTERN: re.Pattern[str] = re.compile(r'^(?:[a-zA-Z]:)?[\\/](?:[^<>:"|?*\n]+[\\/])*[^<>:"|?*\n]*$')

The nested quantifiers (?:[^<>:"|?*\n]+[\\/])* and [^<>:"|?*\n]* operating on overlapping character sets could cause exponential time complexity with malicious input like /aaaaaaaaaaaaa!.

Solution

  1. Simplified PATH_PATTERN to only match the path prefix (lines 57-60)
  2. Added _is_valid_path_string() helper function (after line 202) that validates forbidden characters separately without complex regex
  3. Updated string_to_path() to use the safe validation helper
  4. Updated reconstruct_special_type() to use the safe path validation

Security Impact

  • CWE-1333: Inefficient Regular Expression Complexity
  • Severity: High
  • Fixed by: Eliminating nested quantifiers and using bounded string validation instead

Testing

Added comprehensive regression tests in test_type_utils.py:

  • ReDoS attack pattern completes quickly (< 1 second)
  • Forbidden characters are properly rejected
  • Legitimate paths continue to work correctly
  • Both string_to_path() and reconstruct_special_type() use safe validation

Validation

To run the full test suite:

cd packages/extended-data
pytest tests/core/test_type_utils.py::TestReDoSRegression -v

References

Note: No CodeQL alert suppression was used - the vulnerability was fixed at the source.

@amazon-q-developer

Copy link
Copy Markdown
Author

Resolves Issue #68

@sonarqubecloud

Copy link
Copy Markdown

@jbdevprimary

Copy link
Copy Markdown
Contributor

Superseded by the reviewed and released ReDoS hardening in #79 and #81 (now published in extended-data 8.5.4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant