Repository navigation
Conversation
The project database name was concatenated into SQL as a quoted identifier without escaping embedded quotes, and into a string literal. Double embedded quotes and pass the literal as a bind parameter. Addresses Sonar java:S2077. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
DatabaseDefinitionServicebuilt SQL from the project id by concatenation:databaseProjectStringwrappedprefix_projectIdin double quotes without escaping quotes inside it, anddeleteProjectDatabasealso spliced that into a string literal for thepg_stat_activityquery. The REST controllers only let^[\w-]+$ids through, but nothing in this class enforced it.databaseProjectStringnow doubles any"in the name, so the value can never close the quoted identifier (used byCREATE DATABASEandDROP DATABASE, which cannot take bind parameters).pg_terminate_backendquery is aPreparedStatementwith the name bound as a parameter.SonarCloud issues (
java:S2077):AaHWUyNv45Pg1SGp66jt(:95) is removed by the bind parameter.AaHWUyNv45Pg1SGp66ju(:98,DROP DATABASE) is still dynamically built, since an identifier cannot be bound, so Sonar may keep reporting it; with the escaping in place it is a candidate to mark as reviewed/safe.Why it is safe
^[\w-]+$, no quotes) the generated SQL and the bound value are identical to before; the 60 s query timeout is kept on both statements.DatabaseDefinitionServiceTest(first test inrdb, hence thespring-boot-starter-testtest dependency other modules already use) checks: theDROP DATABASEtext is unchanged for a valid id, the Postgres path binds the name instead of concatenating it, and an id containing"stays inside the identifier../gradlew :rdb:testpasses (3 tests).Noticed, not changed
The terminate query compares
datnamewith the name including its double quotes ('"mms_p1"'), before and after this PR, so it looks like it can never match a database and never terminates anything. I kept the value as is to leave behaviour unchanged here; fixing it would start terminating open connections before the drop and deserves its own change.Implemented in session Get SonarCloud analysis landing for exec-mms
Review with Devin · Open in Devin Desktop