Skip to content

[WRONG BRANCH] fix(codex): prevent TOML string regex backtracking - #316

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-catastrophic-backtracking-in-toml-regex
Draft

[WRONG BRANCH] fix(codex): prevent TOML string regex backtracking#316
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-catastrophic-backtracking-in-toml-regex

Conversation

@luvs01

@luvs01 luvs01 commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Eliminate a ReDoS vector in the TOML basic-string matcher where the non-escape alternative allowed backslashes and could trigger catastrophic backtracking on unterminated quoted strings.

Description

  • Tighten the quoted basic-string branch in tomlStringPattern to exclude backslash so the pattern becomes "(?:\\.|[^"\\])*" instead of "(?:\\.|[^"])*".
  • Add tests/codex-injected-marker.test.ts with regression coverage that decodes escaped Windows-style paths and rejects unterminated basic strings with long backslash runs.

Testing

  • Ran bun test tests/codex-injected-marker.test.ts and the two tests passed.
  • Ran bun run typecheck and bun run privacy:scan and both succeeded, and git diff --check reported no issues.

Codex Task

Summary by CodeRabbit

  • Bug Fixes

    • Improved TOML parsing for strings containing escaped quotes and backslashes.
    • Correctly handles escaped Windows-style paths.
    • Prevents invalid or unterminated strings from being accepted during configuration lookups.
  • Tests

    • Added coverage for escaped strings and malformed strings with long backslash sequences.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 17, 2026
@coderabbitai

coderabbitai Bot commented Aug 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a8d35bd1-2582-45df-8224-821b020f96ce

📥 Commits

Reviewing files that changed from the base of the PR and between 474584b and fbeaadf.

📒 Files selected for processing (2)
  • src/codex/injected-marker.ts
  • tests/codex-injected-marker.test.ts

Included review availability: Your plan includes up to 3 reviews per rolling hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

The TOML string pattern now handles escaped quotes and backslashes correctly. Tests verify escaped Windows-style values and reject unterminated strings for root and provider-table lookups.

Changes

TOML parsing

Layer / File(s) Summary
Escaped string matching and validation
src/codex/injected-marker.ts, tests/codex-injected-marker.test.ts
The regex treats backslash-escaped characters as part of double-quoted TOML strings. Tests cover escaped Windows-style decoding and malformed unterminated strings for root and provider-table lookups.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to fbeaa

The PR narrows TOML string matching to avoid excessive backtracking while preserving escaped-path decoding, with targeted regression coverage; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: ingwannu, lidge-jun, wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: preventing TOML string regex backtracking in Codex.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-catastrophic-backtracking-in-toml-regex

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot changed the title fix(codex): prevent TOML string regex backtracking [WRONG BRANCH] fix(codex): prevent TOML string regex backtracking Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions
github-actions Bot marked this pull request as draft August 17, 2026 12:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fbeaadf014

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// the raw bytes back returned a path that matched nothing on disk and made the
// journal's recorded catalog path un-restorable (#1798).
return new RegExp(`^\\s*${keyToken}\\s*=\\s*("(?:\\\\.|[^"])*"|'[^']*')\\s*(?:#.*)?$`);
return new RegExp(`^\\s*${keyToken}\\s*=\\s*("(?:\\\\.|[^"\\\\])*"|'[^']*')\\s*(?:#.*)?$`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Harden the remaining root TOML matcher

When config.toml contains an unterminated model_catalog_json basic string followed by a backslash run, this change protects only rootTomlString and providerTableString; readRootTomlString in src/codex/paths.ts:136 retains the same overlapping (?:\\.|[^"])* alternatives. The catalog and routing paths call that helper, so even a few dozen backslashes still cause exponential matching and can stall the proxy. Apply the same backslash exclusion to that matcher and cover the exported helper in the regression test.

Useful? React with 👍 / 👎.

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

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant