-
Notifications
You must be signed in to change notification settings - Fork 482
fix(content-drive): fold folder-scoped candidate resolution into a materialized CTE (#37229) #37397
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
Open
ihoffmann-dot
wants to merge
5
commits into
issue-37229-content-drive-folder-cte
Choose a base branch
from
issue-37229-content-drive-folder-cte-impl
base: issue-37229-content-drive-folder-cte
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+359
−25
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b5d1935
fix(content-drive): fold folder-scoped candidate resolution into a ma…
ihoffmann-dot 0ffff94
fix(content-drive): fix real bugs found running BrowserAPITest permis…
ihoffmann-dot 95b6031
chore: trigger CI re-run (retry Semgrep scan for #37229)
ihoffmann-dot 7bcb119
fix(content-drive): scope the id.id ORDER BY tiebreaker to folder-sco…
ihoffmann-dot e84f188
chore: trigger CI re-run (retry Semgrep scan for #37229, after /fp tr…
ihoffmann-dot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Semgrep identified a blocking 🔴 issue in your code:
baseQueryconcatenatesworkingLiveInodeandcandidatesCteinto SQL syntax without constraining their contents. An attacker who controls either value may inject SQL clauses, bypass joins and filters, or read unintended tables.More details about this
baseQuerybuilds SQL by appendingworkingLiveInodedirectly aftercvi.and also embedscandidatesCteas the query prefix. These values are treated as SQL syntax rather than data; if either can be influenced by a request or another untrusted source, an attacker can alter the query structure instead of selecting only the intended inode column.For example, if an attacker can reach
workingLiveInodethrough a query parameter, they could submit a value such aslive_inode FROM sensitive_table --.StringBuilderwould produceselect cvi.live_inode FROM sensitive_table -- as inode ...; the--comments out the remaining SQL, allowing the attacker to change the table being read and bypass the intended joins and filters. Similarly, an attacker-controlledcandidatesCtesuch asWITH candidates AS (...)could inject arbitrary CTE SQL before theselectassembled bybaseQuery, potentially exposing or altering data through the resulting query.The same dynamic identifier is inserted again in
baseClause(cvi.+workingLiveInode), so one attacker-controlled value changes multiple parts of the generated statement. The risk is present even though the matched text is the literal"select cvi.": the following.append(workingLiveInode)makes the complete SQL statement dynamic.To resolve this comment:
✨ Commit fix suggestion
View step-by-step instructions
Validate
workingLiveInodeagainst a fixed allowlist of column names before appending it to the query. Do not use the raw method argument as a SQL identifier; reject any value that is not an expected identifier such aslive_inodeorworking_inode.Restrict
candidatesCteto SQL fragments generated by this application. Prefer selecting between fixed query fragments, for example""and a predefined CTE constant, instead of accepting arbitrary SQL text from a caller.Keep SQL structure in fixed constants and append only validated identifiers or trusted fragments. For example, build the query from a fixed
SELECTtemplate after validatingworkingLiveInodeandidentifierSource, rather than allowing untrusted text to reachnew StringBuilder(...).Validate
baseTypesas numeric values derived from theBaseContentTypeenum before appending them. Do not append arbitrary strings to theINclause.Parameterize
contentTypeIdsandexcludedContentTypeIdsinstead of concatenating them inside quoted SQL. Generate placeholders such as:contentTypeId0, bind each ID through the query’s existingparamsmechanism, and append only the placeholders to the SQL.Apply the same validation and parameter binding to every later
baseQuery.append(...)operation so the completed query contains only fixed SQL syntax, validated identifiers, placeholders, and bound values. This prevents input values from being interpreted as SQL code.💬 Ignore this finding
Reply with Semgrep commands to ignore this finding.
/fp <comment>for false positive/ar <comment>for acceptable risk/other <comment>for all other reasonsAlternatively, triage in Semgrep AppSec Platform to ignore the finding created by CUSTOM_INJECTION-2.
If this is a critical or high severity finding, please also link this issue in the #security channel in Slack.
You can view more details about this finding in the Semgrep AppSec Platform.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/fp Neither concatenated value is attacker-controlled.
workingLiveInodeis assigned from a fixed ternary (browserQuery.showWorking || browserQuery.showArchived ? "working_inode" : "live_inode") — it can never be anything other than those two hardcoded column names, and this concatenation pattern already existed before this PR.candidatesCteis assembled entirely from fixed SQL text plus parameterized predicates: every append helper that contributes to it (appendFolderQuery, appendSiteQuery, appendFileNameQuery) binds values via?placeholders into theparameterslist, never inlining caller input into the SQL string. No request data reaches either value as syntax.