-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Go: Add BigQuery as a sink for SQLi queries #2 #19561
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
Go: Add BigQuery as a sink for SQLi queries #2 #19561
Conversation
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.
Pull Request Overview
This PR adds support for treating cloud.google.com/go/bigquery.Client.Query as a SQL-injection sink in CodeQL analyses, along with test scaffolding, expected outputs, and a change note.
- Introduce a Go test module (
bigquery.go,go.mod) demonstrating an untrusted string passed toClient.Query. - Add CodeQL test query (
bigquery.ql) and sink model (cloud.google.com.go.bigquery.model.yml) to markQueryas an SQLi sink. - Provide test expectations and change notes (
*.expected,*.md).
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| go/ql/test/library-tests/semmle/go/frameworks/SQL/bigquery/go.mod | New module with BigQuery dependency for tests |
| go/ql/test/library-tests/semmle/go/frameworks/SQL/bigquery/bigquery.ql | CodeQL test that matches calls to BigQuery Query |
| go/ql/test/library-tests/semmle/go/frameworks/SQL/bigquery/bigquery.go | Example Go code invoking Query with untrusted data |
| go/ql/test/library-tests/semmle/go/frameworks/SQL/bigquery/bigquery.expected | Expected test output for the BigQuery sink |
| go/ql/test/library-tests/semmle/go/frameworks/SQL/bigquery/QueryString.ql | Test modules for SQL::QueryString and dataflow validation |
| go/ql/test/library-tests/semmle/go/frameworks/SQL/bigquery/QueryString.expected | Expected results placeholder for QueryString tests |
| go/ql/lib/ext/cloud.google.com.go.bigquery.model.yml | Extension model marking Client.Query as a SQLi sink |
| go/ql/lib/change-notes/2025-05-22-bigquery-client-query-sql-injection.md | Documentation of the newly recognized sink |
Comments suppressed due to low confidence (2)
go/ql/test/library-tests/semmle/go/frameworks/SQL/bigquery/bigquery.ql:3
- [nitpick] The variables
aandbare not descriptive. Consider renaming them topackageNameandfunctionName(or similar) to clarify their roles inhasQualifiedName.
from SQL::QueryString qs, Function func, string a, string b
go/ql/test/library-tests/semmle/go/frameworks/SQL/bigquery/QueryString.ql:24
- This forces
elementto be empty, which prevents capturing the actual query string in the QueryString test. Update this toelement = qs.toString()(or remove the filter) so the test can validate the real value.
element = "" and
Click to show differences in coveragegoGenerated file changes for go
+ `bigquery <https://pkg.go.dev/cloud.google.com/go/bigquery>`_,``cloud.google.com/go/bigquery*``,,,1
- `gorqlite <https://github.com/rqlite/gorqlite>`_,"``github.com/raindog308/gorqlite*``, ``github.com/rqlite/gorqlite*``",16,4,48
+ `gorqlite <https://github.com/rqlite/gorqlite>`_,"``github.com/raindog308/gorqlite*``, ``github.com/rqlite/gorqlite*``, ``github.com/kanikanema/gorqlite*``",24,6,72
- Others,``github.com/kanikanema/gorqlite``,8,2,24
- Totals,,688,1069,1556
+ Totals,,688,1069,1557
+ cloud.google.com/go/bigquery,1,,,,,,,,,,,,,,1,,,,,,,,,,,, |
Also fix up github.com/kanikanema/gorqlite
Napalys
left a comment
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.
LGTM 👍
Just couple quick questions:
QueryString.qlfile is something you drag along for inline tests?- The column within
MaDwhich states manual, that one implies that the followingMaDwas added manually or does it mean something else?
|
mbg
left a comment
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.
Couple of questions here:
- If the
QueryString.qlpart is shared between multiple tests and there's nothing specific to this, would it make sense to move this to a shared location and have the code shared among tests, rather than duplicated? - This may be a lack of understanding on my part of how all this fits together, but is there anything that's checking that the new sink is correctly identified as part of a SQL injection query? As far as I can tell, the
bigquery.qltest only checks that the argument is correctly identified as a query string?
|
mbg
left a comment
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.
Happy to approve this as is and leave the improvements to future work.
Do you have any suggestions for where to share it?
I believe we have some shared test code ql/lib/utils/test where this could go as well? The individual test folders could then contain a reference to that, or query which imports the implementation from the shared location. The main goal would be to avoid duplicating large amounts of code across tests.
It sounds like you are thinking of query tests for SQL injection which are in go/ql/test/query-tests/Security/CWE-089/. We do not currently test for the many different SQL frameworks in that query test. You could argue that we could, but I think it is too much work for this PR to reorganise the tests.
Yes, indeed. I would argue that this would make sense, since for many queries we already have tests for different frameworks. If we don't already have full database framework coverage for CWE-089, then I agree that it wouldn't make sense to address this as part of this PR.
Supersedes #18460.