Skip to content

JS: Diff-informed queries: phase 3 (non-trivial locations) #20078

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

Closed
wants to merge 4 commits into from

Conversation

d10c
Copy link
Contributor

@d10c d10c commented Jul 17, 2025

This PR enables diff-informed mode on queries that select a location other than dataflow source or sink. This entails adding a non-trivial location override that returns the locations that are actually selected.

Prior work includes PRs like #19663, #19759, and #19817. This PR uses the same patch script as those PRs to find candidate queries to convert to diff-enabled. This is the final step in mass-enabling diff-informed queries on all the languages.

Commit-by-commit reviewing is recommended.

  • I have split the commits that add/modify tests from the ones that enable/disable diff-informed queries.
  • If the commit modifies a .qll file, in the commit message I've included links to the queries that depend on that .qll for easier reviewing.
  • Feel free to delegate parts of the review to others who may be more specialized in certain languages.

@github-actions github-actions bot added the JS label Jul 17, 2025
@d10c d10c added the no-change-note-required This PR does not need a change note label Jul 17, 2025
@d10c d10c marked this pull request as ready for review July 17, 2025 14:11
@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 14:11
@d10c d10c requested a review from a team as a code owner July 17, 2025 14:11
@d10c d10c requested a review from michaelnebel July 17, 2025 14:11
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 enables diff-informed mode on JavaScript queries that select locations other than dataflow sources or sinks by implementing non-trivial location overrides. The changes add the necessary predicates to support diff-informed incremental analysis while ensuring proper location reporting for query results.

Key changes:

  • Adds observeDiffInformedIncrementalMode() predicates to enable/disable diff-informed mode on specific queries
  • Implements getASelectedSinkLocation() methods to override location selection for queries with custom highlighting logic
  • Refactors location selection logic to handle cases where custom sink highlighting is available

Reviewed Changes

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

File Description
decodeJwtWithoutVerification.ql Disables diff-informed mode due to secondary config usage
EnvValueAndKeyInjection.ql Disables diff-informed mode due to complex location override requirements
ShellCommandInjectionFromEnvironmentQuery.qll Enables diff-informed mode and refactors location selection logic
IndirectCommandInjectionQuery.qll Enables diff-informed mode and refactors location selection logic

isSinkWithHighlight(sink, node) and
result = node.getLocation()
exists(DataFlow::Node highlight | result = highlight.getLocation() |
if isSinkWithHighlight(sink, _)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this changed needed?
According to the data flow configuration the sink nodes are exactly those where isSinkWithHighlight(sink, _) holds.

Copy link
Contributor

Choose a reason for hiding this comment

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

It also seems off to me. The change causes getASelectedSinkLocation to contain an entry all data flow nodes. It should be restricted to those that are sinks, which it was to begin with.

Copy link
Contributor Author

@d10c d10c Aug 14, 2025

Choose a reason for hiding this comment

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

Ok, I see. The original query contains:

  if IndirectCommandInjectionConfig::isSinkWithHighlight(sink.getNode(), _)
  then IndirectCommandInjectionConfig::isSinkWithHighlight(sink.getNode(), highlight)
  else highlight = sink.getNode()

which is what this diff does. But isSinkWithHighlight is sink = highlight or isIndirectCommandArgument(sink, highlight), so you can't have not isSinkWithHighlight(sink, _) and highlight = sink). So the original is correct.

exists(DataFlow::Node node |
isSinkWithHighlight(sink, node) and
result = node.getLocation()
exists(DataFlow::Node highlight | result = highlight.getLocation() |
Copy link
Contributor

Choose a reason for hiding this comment

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

same question.

@asgerf
Copy link
Contributor

asgerf commented Aug 14, 2025

This was already implemented for JS in #18528 and #18574.

@d10c
Copy link
Contributor Author

d10c commented Aug 14, 2025

Since this PR adds nothing new to #18574, I will close it.

@d10c d10c closed this Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants