Skip to content

fix(research_extensions): read on: brackets outside comments and quotes - #1039

Merged
hyperpolymath merged 3 commits into
mainfrom
claude/eager-wright-zwwbe2-nesting-at
Nov 9, 2026
Merged

hyperpolymath merged 3 commits into
mainfrom
claude/eager-wright-zwwbe2-nesting-at

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Summary

This is the follow-up named in #1027.

Hypatia.WorkflowYaml.nesting_at/2 counts every bracket it is given. Callers must therefore pass text with comments and quoted scalars blanked, as its doc now says. RE001's trigger reader passed raw text in three places:

Where Input Effect on main
Continuation line of a multi-line on: [...] workflow_dispatch] # was pull_request_target A phantom pull_request_target trigger becomes an untrusted-input exposure.
Same workflow_dispatch] # see [ops notes The bracket stays open and the reader swallows the rest of the file. A run: ./issue_comment.sh line then becomes an issue_comment trigger.
Inline on: {...} map {push: {tags: ["v1.0]"]}, issue_comment: …} The depth is shifted, so the real top-level issue_comment is dropped.
A step's flow with: {...} a quoted ] or [ Same miscount when deciding whether the mapping continues.

Only whole-line comments are dropped before a rule reads a workflow (active_lines/1). Trailing comments on continuation lines therefore reached both the bracket count and the event-word scan.

Fix

  • Each continuation line is passed through strip_yaml_comment/1 before it is appended. The on: line uses the same function instead of a \s+# regex.
  • A new open_flow?/1 reads the depth after blanking quoted scalars with strip_yaml_comment(_, true). Byte offsets are preserved. Both continuation readers use it: the on: reader and the with: reader.
  • inline_events/1 takes key names from the raw map but the depth from its blanked copy.

Verification

  • Four new RE001 tests:

    • a positive control: an issue_comment on a continuation line with a balanced [bot] comment is still an exposure;
    • three decoys from the table above.

    On main the three decoys fail and the control passes. On this branch all four pass.

  • research_extensions_test: 122/122. Compiled standalone with elixirc --warnings-as-errors because hex.pm is unreachable here. mix format --check-formatted is clean.

  • RE001 findings over five real trees, before and after, are identical: 18 findings across hypatia, standards, echidna, gitbot-fleet and mathesis.

Aspect notes

  • Type/proof route: the cleaner fix is a type distinction between raw line text and "code" text. A caller could then not hand raw text to nesting_at/2 at all. In Elixir that is a tagged tuple or a struct at the WorkflowYaml boundary. It touches every caller of the shared reader (WH and RE rules), so it is better as its own change than folded into this fix.


Generated by Claude Code

…otes

`Hypatia.WorkflowYaml.nesting_at/2` counts every bracket it is given, so
callers must pass text with comments and quoted scalars blanked (its doc
says so since #1027). RE001's trigger reader passed raw text in three places.

Each place had a failure mode:
- Continuation lines of a multi-line `on: [...]`: only whole-line comments
  are dropped before the rule reads a workflow, so a trailing comment
  reached both the bracket count and the event scan.
  - `issues]  # was pull_request_target` named a trigger that is not there.
  - `]  # see [ops notes` left a bracket open, so the reader swallowed the
    rest of the file and took words from `run:` lines as events.
- Inline `on: {...}` maps: a bracket inside a quoted scalar
  (`tags: ["v1.0]"]`) shifted the depth, and a real top-level event key
  was dropped.
- Flow `with:` mappings on a step: they had the same quoted-bracket
  miscount when deciding whether the mapping continues.

The fix strips each continuation line's comment, and reads the depth
through `open_flow?/1`, which blanks quoted scalars first
(`strip_yaml_comment/2`, offsets preserved).

Tests:
- 4 new RE001 tests: a positive control plus 3 decoys. The 3 decoys fail
  on main; the control passes on both.
- research_extensions_test: 122/122. It compiles with --warnings-as-errors,
  and `mix format --check-formatted` is clean.
- RE001 findings on hypatia, standards, echidna, gitbot-fleet and mathesis
  are identical before and after (18 findings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CYR5bf5FBLS7cXQK72aVNM
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8b0b1d6f-1366-4ff0-8d36-f477b7bcfcd1
Commits

Reviewing files that changed from the base of the PR and between 49a495b and db29b2b.

Files selected for processing: 2

  • lib/rules/research_extensions.ex
  • test/research_extensions_test.exs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@hyperpolymath
hyperpolymath marked this pull request as ready for review November 9, 2026 15:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T21:41:59.004977Z db29b2b New commits
🔒 Security Review ❌ Failed 2026-11-09T21:38:16.793312Z
We couldn’t complete this review. Comment @codex security review to try again.
db29b2b New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: be443dc386

ℹ️ 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".

Comment thread lib/rules/research_extensions.ex Resolved
Comment thread lib/rules/research_extensions.ex Resolved
Codex found two cases the line-by-line comment stripping missed:

- A quoted scalar spanning lines lost its quote state at the line break,
  so `foo #hi"}}}, issue_comment: {}}` was cut at `#`. The closing quote,
  the braces and the issue_comment event went with it.
- An apostrophe inside a plain scalar (`description: Say 'hi`) opened a
  quote, blanked the structure after it, and hid a later top-level event.

flow_text/2 replaces strip_yaml_comment/2 for flow values. It scans the
whole value, carrying quote state across newlines. A quote opens a scalar
only where a flow node starts, at the start or after `{`, `[`, `,` or `:`.
A ` #` outside quotes starts a comment that ends at its own line. Byte
offsets are preserved, so the depth and key positions line up as before.

Two new tests reproduce the findings and fail on be443dc; 124/124 pass.
`mix format` is clean and the code compiles with --warnings-as-errors.
RE001 findings on hypatia, standards, echidna, gitbot-fleet and mathesis
are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CYR5bf5FBLS7cXQK72aVNM

@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: 72d632a64b

ℹ️ 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".

Comment on lines +914 to +915
:plain when c in [?', ?"] and sig in [nil, ?{, ?[, ?,, ?:] ->
flow_scan(rest, b, {:quote, c}, c, c, [c | acc])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize anchors before quoted flow scalars

When an inline on: map anchors a quoted node, such as description: &text "[draft", sig contains the final anchor-name byte, so this condition does not recognize the opening quote. The bracket intended as scalar text is then counted as flow syntax, causing a later top-level key such as issue_comment to be evaluated at the wrong depth and omitted from workflow_events; RE001 consequently misses the untrusted-trigger exposure for credential-bearing jobs. Account for anchor and tag properties when determining whether a quoted scalar starts here.

Useful? React with 👍 / 👎.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Add Carrot credits or activate Agent usage billing to use Autofix

Repository owner deleted a comment from chatgpt-codex-connector Bot Nov 9, 2026
@hyperpolymath
hyperpolymath enabled auto-merge (squash) November 9, 2026 21:38
@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

Repository owner deleted a comment from chatgpt-codex-connector Bot Nov 9, 2026
Repository owner deleted a comment from chatgpt-codex-connector Bot Nov 9, 2026
@hyperpolymath
hyperpolymath merged commit be6510f into main Nov 9, 2026
93 checks passed
@hyperpolymath
hyperpolymath deleted the claude/eager-wright-zwwbe2-nesting-at branch November 9, 2026 21:48
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.

3 participants