Skip to content

Ruby: disable diff-informed mode on regex queries #19416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

jbj
Copy link
Contributor

@jbj jbj commented Apr 30, 2025

These queries were failing in codeql test run --check-diff-informed because they can select locations inside the regex. Until that can be fixed, diff-informed mode is disabled for these queries.

I didn't add a code comment with details about the problem because I didn't investigate it in full detail, but I presume it's overall the same story as in #19379.

Cc @d10c @cklin @asgerf

These queries were failing in `codeql test run --check-diff-informed`
because they can select locations inside the regex. Until that can be
fixed, diff-informed mode is disabled for these queries.
@Copilot Copilot AI review requested due to automatic review settings April 30, 2025 07:28
@jbj jbj requested a review from a team as a code owner April 30, 2025 07:28
@jbj jbj added no-change-note-required This PR does not need a change note Ruby labels Apr 30, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR disables diff-informed mode for two regex queries to resolve failures during diff-informed testing. The changes remove the predicate observeDiffInformedIncrementalMode and associated location selection logic from both the PolynomialReDoSQuery and MissingFullAnchorQuery modules.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
ruby/ql/lib/codeql/ruby/security/regexp/PolynomialReDoSQuery.qll Removed diff-informed predicates and location getter logic.
ruby/ql/lib/codeql/ruby/security/regexp/MissingFullAnchorQuery.qll Removed diff-informed predicates and location getter logic.
Comments suppressed due to low confidence (2)

ruby/ql/lib/codeql/ruby/security/regexp/PolynomialReDoSQuery.qll:19

  • The removal of the diff-informed predicate appears intentional; please confirm that no downstream consumers depend on observeDiffInformedIncrementalMode or the removed getASelectedSinkLocation logic.
predicate observeDiffInformedIncrementalMode() { any() }

ruby/ql/lib/codeql/ruby/security/regexp/MissingFullAnchorQuery.qll:19

  • Ensure that the removal of diff-informed mode components does not affect any components expecting the location selection logic that was provided by getASelectedSinkLocation.
predicate observeDiffInformedIncrementalMode() { any() }

Copy link
Contributor

@asgerf asgerf left a comment

Choose a reason for hiding this comment

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

Seems to be the same issue: RegExpTerm has both getLocation() and hasLocationInfo but they're not the same.

getLocation() however does enclose the hasLocationInfo location (which is a subterm in the regexp), but alert filtering in testing mode expects an exact match, not an overlap. I think in production this would actually work because there we check for overlap (at line granularity) not exactness.

Approving to unblock a potentially failing CI but I believe the proper fix is to improve on the AlertFiltering to check for overlap.

@jbj
Copy link
Contributor Author

jbj commented Apr 30, 2025

We agreed offline that checking for (line-granularity) containment is not the answer. That's because diff-informed queries follows the behaviour of code scanning on PRs where only the start line matters, not the end line, so containment would just mean start line equality. In the case of these regex queries, we would lose results on multi-line regexes. More generally, we would lose results whenever the contained location doesn't start on the same line as the container.

@jbj jbj merged commit c8e564b into github:main Apr 30, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Ruby
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants