Add Hibernate SQL injection sink models and coverage#21749
Add Hibernate SQL injection sink models and coverage#21749
Conversation
Agent-Logs-Url: https://github.com/github/codeql/sessions/2e7aecca-63ea-489f-8b87-4cc557655919 Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
|
@copilot That's great. Now please do the following task in new commits. I have noticed that there are no models for sql-injection sinks for these methods (and overloaded variants if any): For each such method, consider whether it should be an sql-injection sink. If so, add a model for it in |
Agent-Logs-Url: https://github.com/github/codeql/sessions/fc2c7f71-3493-4bf7-9136-34571a1d4b47 Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
Addressed in 25d232b. I added Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot Add a library change note. There is guidance in |
Agent-Logs-Url: https://github.com/github/codeql/sessions/41769e74-a435-4aaf-b5f7-92060f6cd84e Co-authored-by: owen-mc <62447351+owen-mc@users.noreply.github.com>
owen-mc
left a comment
There was a problem hiding this comment.
I manually checked that the tests are actually doing something by removing the inline expectation comments and rerunning the tests in that folder. One of the tests failed.
There was a problem hiding this comment.
Pull request overview
Adds regression coverage for Hibernate SQL/HQL injection sinks in the Java CWE-089 test suite, and extends the Hibernate QueryProducer sink models so the sql-injection query flags additional executable query construction APIs.
Changes:
- Extended Hibernate sink modeling to treat additional
QueryProducermethods assql-injectionsinks. - Added a focused CWE-089 example (
Hibernate.java) that exercises all modeled Hibernate sink entry points with inline expectations. - Introduced minimal Hibernate stubs and updated the CWE-089 examples classpath to compile the new example.
Show a summary per file
| File | Description |
|---|---|
| java/ql/lib/ext/org.hibernate.query.model.yml | Adds sink models for additional QueryProducer methods (createNativeMutationQuery, createMutationQuery, createSelectionQuery). |
| java/ql/lib/change-notes/2026-04-23-hibernate-queryproducer-sinks.md | Documents the new sink models in change notes. |
| java/ql/test/query-tests/security/CWE-089/semmle/examples/Hibernate.java | Adds a new regression example exercising Hibernate sinks with // $ sqlInjection markers. |
| java/ql/test/query-tests/security/CWE-089/semmle/examples/options | Extends the examples classpath to include the new Hibernate stubs. |
| java/ql/test/stubs/hibernate-5.x/org/hibernate/Session.java | Minimal stub for Session with sink-relevant methods. |
| java/ql/test/stubs/hibernate-5.x/org/hibernate/SharedSessionContract.java | Minimal stub for SharedSessionContract with sink-relevant methods and QueryProducer relationship. |
| java/ql/test/stubs/hibernate-5.x/org/hibernate/query/QueryProducer.java | Minimal stub covering the QueryProducer methods exercised by the regression test. |
| java/ql/test/stubs/hibernate-5.x/org/hibernate/query/Query.java | Minimal stub type needed for compilation. |
| java/ql/test/stubs/hibernate-5.x/org/hibernate/query/MutationQuery.java | Minimal stub type needed for compilation. |
| java/ql/test/stubs/hibernate-5.x/org/hibernate/query/SelectionQuery.java | Minimal stub type needed for compilation. |
Copilot's findings
- Files reviewed: 10/10 changed files
- Comments generated: 0
The Java
sql-injectionquery already modeled some Hibernate sinks inSqlTainted.ql, but the CWE-089 regression tests did not exercise those APIs. This PR adds focused regression coverage for the existing Hibernate sinks injava/ql/test/query-tests/security/CWE-089/semmle/examplesand also extends the Hibernate sink modeling for additionalQueryProducermethods that should be treated as SQL-injection sinks.Hibernate sink model updates
sql-injectionsink models injava/ql/lib/ext/org.hibernate.query.model.ymlfor:QueryProducer.createNativeMutationQueryQueryProducer.createMutationQueryQueryProducer.createSelectionQueryStringargument, so they should be treated as SQL-injection sinks.New Hibernate regression example
Hibernate.javaunder the existing CWE-089 examples directory.Session.createQuerySession.createSQLQuerySharedSessionContract.createQuerySharedSessionContract.createSQLQueryQueryProducer.createNativeQueryQueryProducer.createNativeMutationQueryQueryProducer.createQueryQueryProducer.createMutationQueryQueryProducer.createSelectionQueryQueryProducer.createSelectionQuery(String, Class)QueryProducer.createSQLQueryMinimal test stubs
java/ql/test/stubs/hibernate-5.xfor:org.hibernate.Sessionorg.hibernate.SharedSessionContractorg.hibernate.query.QueryProducerorg.hibernate.query.Queryorg.hibernate.query.MutationQueryorg.hibernate.query.SelectionQueryExamples classpath update
optionsfile to include the new Hibernate stub path so the new test source compiles with the existing example set.Example added to the regression suite:
Original prompt
Created from VS Code.