Skip to content

C++: Support SQL Injection sinks for Oracle Call Interface (OCI) #19832

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

Merged
merged 6 commits into from
Jun 26, 2025

Conversation

ebickle
Copy link
Contributor

@ebickle ebickle commented Jun 20, 2025

Fixes #19764

  • Allow queries to be extended using a new sql-injection Models as Data (MaD) sink kind for C/C++.
  • Add sql-injection sink models for the Oracle Call Interface (OCI) database library functions OCIStmtPrepare and OCIStmtPrepare2.

@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 13:08
@ebickle ebickle requested a review from a team as a code owner June 20, 2025 13:08
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 introduces support for SQL injection sinks for Oracle Call Interface (OCI) in C/C++ by adding models for the OCIStmtPrepare and OCIStmtPrepare2 functions. Key changes include:

  • Adding OCI function prototypes and test cases in test.c to trigger both vulnerable (BAD) and safe (GOOD) patterns.
  • Updating expected taint flow edges in the SqlTainted.expected file.
  • Extending the CodeQL model through modifications in SqlTainted.ql, Oracle.oci.model.yml, and change notes documentation.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cpp/ql/test/query-tests/Security/CWE/CWE-089/SqlTainted/test.c Added OCI function prototypes and test cases for OCIStmtPrepare and OCIStmtPrepare2 including taint tracking for SQL injection.
cpp/ql/test/query-tests/Security/CWE/CWE-089/SqlTainted/SqlTainted.expected Updated expected taint flow edge definitions to include new OCI models.
cpp/ql/src/change-notes/2025-06-20-sql-injection-models.md Documented extension of sql-injection sink support through Models as Data.
cpp/ql/src/Security/CWE/CWE-089/SqlTainted.ql Enhanced sink configuration to include the new "sql-injection" model.
cpp/ql/lib/ext/Oracle.oci.model.yml Added sink models for OCIStmtPrepare and OCIStmtPrepare2 functions with sql-injection kind.
cpp/ql/lib/change-notes/2025-06-20-oracle-oci-models.md Documented the addition of OCI sql-injection sink models.

}

// Oracle Call Interface (OCI) Routines
int OCIStmtPrepare(
Copy link
Preview

Copilot AI Jun 20, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider moving the Oracle OCI function prototypes to a dedicated header file to improve maintainability and reduce duplication in test code.

Copilot uses AI. Check for mistakes.

@geoffw0
Copy link
Contributor

geoffw0 commented Jun 26, 2025

Changes LGTM, as does the DCA run. Looks like a valuable extension.

Not sure why three CI checks are failing, it doesn't look like it has anything to do with the changes here. I'll try rerunning them.

@jketema would you might checking this and approving, since I wrote some of the changes so it would be good to have a third opinion here.

@jketema
Copy link
Contributor

jketema commented Jun 26, 2025

Not sure why three CI checks are failing, it doesn't look like it has anything to do with the changes here. I'll try rerunning them.

Looks like this has to do with some internal changes we made. I've merged in the latest main, which hopefully resolves this.

jketema
jketema previously approved these changes Jun 26, 2025
@jketema
Copy link
Contributor

jketema commented Jun 26, 2025

One remaining test failure. This is a genuine one for cpp/ql/test/library-tests/dataflow/external-models/flow.ql Its .expected file will need to be updated.

@geoffw0
Copy link
Contributor

geoffw0 commented Jun 26, 2025

Oh that's annoying, it's a test that outputs the MaD row IDs (which are not stable when models are added).

@ebickle do you know how to accept the changes to cpp/ql/test/library-tests/dataflow/external-models/flow.expected?

@jketema can we remove the MaD IDs from this test, or pretty print them like we do in query tests so that we get more stable output?

@jketema
Copy link
Contributor

jketema commented Jun 26, 2025

@jketema can we remove the MaD IDs from this test, or pretty print them like we do in query tests so that we get more stable output?

Do you have an example of the pretty printing?

@geoffw0
Copy link
Contributor

geoffw0 commented Jun 26, 2025

Do you have an example of the pretty printing?

Rust .qlref files that have:

postprocess:
 - utils/test/PrettyPrintModels.ql

I'm not sure if this is available in C++, nor if it would really do the right thing in this case.

@ebickle
Copy link
Contributor Author

ebickle commented Jun 26, 2025

Oh that's annoying, it's a test that outputs the MaD row IDs (which are not stable when models are added).

@ebickle do you know how to accept the changes to cpp/ql/test/library-tests/dataflow/external-models/flow.expected?

I should be able to accept the changes (codeql test accept) but I keep running into strange test errors on my end.

With a synced fork and the latest CodeQL binaries I keep getting this on random unit tests, including the flow test but not CWE-089:

Executing tests in C:\Users\eric\Source\Repos\ebickle-codeql\cpp\ql\test\examples\BadLocking.
A fatal error occurred: The CodeQL database is not compatible with a QL library referenced by the query you are trying to run.
CodeQL database location: examples\BadLocking\BadLocking.testproj
Query location: ..\src\jsf\4.13 Functions\AV Rule 107.ql
The database may be too new for the QL libraries the query is using; try upgrading them.
Alternatively, running 'codeql database upgrade examples\BadLocking\BadLocking.testproj' with an appropriate --search-path option might help.

This happened on a machine with a fresh install of CodeQL so the "database is not compatible" message likely isn't something on my end. I've tried updating the CodeQL binaries again and nuking my profile's .codeql directory without success. Probably a setup step I missed - any ideas? 😳

I've also tossed an invite to my fork over to the two of you in case you need it.

@ebickle
Copy link
Contributor Author

ebickle commented Jun 26, 2025

I was able to run the test in VS Code - the update for the flow.expected is in.

@jketema
Copy link
Contributor

jketema commented Jun 26, 2025

With a synced fork and the latest CodeQL binaries I keep getting this on random unit tests, including the flow test but not CWE-089:

I think that means it's picking up an old version of the CodeQL C++ library, which doesn't have the necessary downgrade scripts. VSCode apparently picks up the right version automatically.

@jketema
Copy link
Contributor

jketema commented Jun 26, 2025

Do you have an example of the pretty printing?

Rust .qlref files that have:

postprocess:
 - utils/test/PrettyPrintModels.ql

I'm not sure if this is available in C++, nor if it would really do the right thing in this case.

Thanks. That looks doable. I'll have a look once this PR is merged.

@jketema jketema merged commit ec09d36 into github:main Jun 26, 2025
16 checks passed
@jketema
Copy link
Contributor

jketema commented Jun 26, 2025

Merged. @ebickle thanks for your contribution!

@ebickle ebickle deleted the feature/oracle-model branch June 26, 2025 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Oracle Call Interface (OCI) to C/C++ coverage
3 participants