Skip to content

fix(tools): eliminate ReDoS backtracking in tfdoc MARK_OPTS_RE - #414

Merged
Calvin-Cheng1 merged 1 commit into
mainfrom
fix/tfdoc-redos-security
Nov 12, 2026
Merged

Calvin-Cheng1 merged 1 commit into
mainfrom
fix/tfdoc-redos-security

Conversation

@aghassemlouei

Copy link
Copy Markdown
Member

Description

Replaces the nested repetition in MARK_OPTS_RE inside tools/tfdoc.py with an explicit whitespace-delimited key:value sequence so unterminated <!-- TFDOC OPTS markers cannot trigger exponential regular-expression backtracking.

In #311, MARK_OPTS_RE was widened from (?:[a-z_]+:[0-1]\s*?)+ to (?:[a-z_]+:\S+\s*?)+ to support string option values such as exclude:outputs.tf. Because \s*? matches zero characters and \S+ overlaps with [a-z_]+:, adjacent key:value repetitions can split a single non-whitespace token in $2^n$ ways when the closing --> delimiter is absent. Requiring \s+ between option tokens matches the whitespace splitting in get_tfref_opts and makes every quantifier boundary disjoint.

Closes Code Scanning alert #339

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Deployment & Compliance Impact

  • Applicable Regimes:
    • US Region Restricted (e.g., Access Policy constraint)
    • FedRAMP Moderate
    • FedRAMP High
    • DoD IL4
    • DoD IL5
    • General / All
  • NIST 800-53r5 Controls: Not applicable. This change is scoped to repository documentation generation tooling in tools/tfdoc.py.

Checklist

Code Quality & Reusability

  • My code adheres to the Maximize Reusability principle. I have not redefined common elements and have reused existing base configurations and modules where possible.
  • I have checked that no existing module or configuration in modules/ or fast/stages-aw/ can be leveraged for this change.
  • My code follows the established naming conventions outlined in docs/naming-convention.md.

Documentation

  • I have updated the README.md of the modified module or blueprint.
  • I have added/updated documentation for inputs (variables) and outputs.

Security

  • My change adheres to GCP security best practices and the principle of least privilege.
  • I have ensured compliance with the targeted regime (FedRAMP Moderate, FedRAMP High, IL4, IL5, etc.).

Testing

  • I have tested my changes locally.
  • I have included details of my testing in this PR.

Testing Performed

  • Executed tests/test_tfdoc.py covering single-option, multi-option exclude, and 500-repeat unterminated <!-- TFDOC OPTS _: inputs (11/11 passing in 0.004s).
  • Executed the root Python test suite (123/123 passing), ruff format --check, ruff check, tools/check_boilerplate.py, and tools/check_documentation.py --no-show-summary modules fast blueprints.

@aghassemlouei aghassemlouei added Bug Something isn't working Security Something is insecure or can be secured Priority - Medium Standard features and non-blocking bugs; important for the current milestone but not urgent Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete labels Nov 12, 2026
@aghassemlouei aghassemlouei self-assigned this Nov 12, 2026
@aghassemlouei
aghassemlouei marked this pull request as ready for review November 12, 2026 16:55

@mgcarey-google mgcarey-google left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Calvin-Cheng1
Calvin-Cheng1 merged commit c398f11 into main Nov 12, 2026
23 checks passed
@Calvin-Cheng1
Calvin-Cheng1 deleted the fix/tfdoc-redos-security branch November 12, 2026 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Level of Effort - Low Quick, well-defined tasks with no unknowns; takes a few hours up to one day to complete Priority - Medium Standard features and non-blocking bugs; important for the current milestone but not urgent Security Something is insecure or can be secured

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants