Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Add Column, From, JoinClause, *Join, Having, OrderByClause methods for squirrel SQLi query #682

Merged
merged 7 commits into from
Sep 3, 2022

Conversation

lyoung-confluent
Copy link
Contributor

@lyoung-confluent lyoung-confluent commented Feb 3, 2022

Changes

Building on @tunnelshade's work in #611, add a few additional methods with similar signatures/issues.
These are vulnerable sinks if the first parameter is tainted input.
Some of these functions accept interface{} type in which case only string type (StringType) is tainted/vulnerable.

Links

@lyoung-confluent lyoung-confluent requested a review from a team as a code owner February 3, 2022 21:23
Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

I don't have detailed knowledge of the package to know whether the Having and Clause methods perform sufficient escaping of their arguments to prevent a meaningful injection attack: have you tested that they really are exploitable?

@lyoung-confluent
Copy link
Contributor Author

I don't have detailed knowledge of the package to know whether the Having and Clause methods perform sufficient escaping of their arguments to prevent a meaningful injection attack: have you tested that they really are exploitable?

Yes, demo: https://go.dev/play/p/7Ipxor9Z029

Having actually uses the exact same newWhereClause as Where does internally so is vulnerable in the same way: https://github.com/Masterminds/squirrel/blob/v1.5.2/select.go#L351

OrderByClause uses newPart which directly returns the pred (first argument) when ToSQL is invoked if it is a string: https://github.com/Masterminds/squirrel/blob/def598cbb358368fbfc3f6a9a914699a36846992/part.go#L24

@smowton
Copy link
Contributor

smowton commented Feb 7, 2022

👍 ping me when this is in a ready state

@lyoung-confluent
Copy link
Contributor Author

I added "Join", "LeftJoin", "RightJoin", "InnerJoin", "CrossJoin" as well as these functions are all aliases of JoinClause with a small prefix added, ex: https://github.com/Masterminds/squirrel/blob/v1.5.2/select.go#L292

Also From which uses newPart as well: https://github.com/Masterminds/squirrel/blob/v1.5.2/select.go#L275
And finally Columns which also uses newPart: https://github.com/Masterminds/squirrel/blob/v1.5.2/select.go#L260

@lyoung-confluent lyoung-confluent changed the title Add Having, JoinClause, OrderByClause methods for squirrel SQLi query Add Column, From, JoinClause, *Join, Having, OrderByClause methods for squirrel SQLi query Feb 7, 2022
@lyoung-confluent
Copy link
Contributor Author

@smowton I believe it's ready for a round of review/merge (assuming tests pass, currently blocked on github actions being started)

@smowton smowton enabled auto-merge February 8, 2022 10:12
@owen-mc owen-mc self-assigned this Feb 8, 2022
@owen-mc
Copy link
Contributor

owen-mc commented Feb 8, 2022

CI is currently failing when trying to extract ql/test/library-tests/semmle/go/frameworks/SQL/. You need to update the version of Squirrel in ql/test/library-tests/semmle/go/frameworks/SQL/vendor/modules.txt to match the corresponding go.mod. With that change, the tests fail because lines 46-58 of ql/test/library-tests/semmle/go/frameworks/SQL/main.go should have the comment // $ querystring=querypart querystring="users".

@smowton smowton merged commit 4e2ec44 into github:main Sep 3, 2022
@adityasharad adityasharad mentioned this pull request Sep 3, 2022
yo-h added a commit that referenced this pull request Sep 6, 2022
@smowton
Copy link
Contributor

smowton commented Sep 13, 2022

Noting this was merged accidentally due to changes to the automerge criteria and then reverted in #748

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants