fix(java): recognize SharedSessionContract in hibernate-sqli - #4027
Open
Eljees wants to merge 1 commit into
Open
fix(java): recognize SharedSessionContract in hibernate-sqli#4027Eljees wants to merge 1 commit into
Eljees wants to merge 1 commit into
Conversation
The rule only tracked a query built on an org.hibernate.Session, so the same dynamic HQL executed through a SharedSessionContract (the supertype of Session and StatelessSession, and the declared return type used in plenty of code) was a false negative. Add SharedSessionContract next to Session in the receiver-type alternatives, for both the local-variable and method-parameter shapes. The StringBuilder case from the issue is left for a follow-up: tracking a query assembled through StringBuilder.append/toString needs more than a receiver-type addition and is better handled separately. Signed-off-by: Eljees <3.14hell@gmail.com>
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.
Addresses case 1 of #3817.
Problem
hibernate-sqlionly tracks a dynamic query when the receiver is typed asorg.hibernate.Session. The same HQL executed through aSharedSessionContractis missed:SharedSessionContractis the common supertype ofSessionandStatelessSessionand is a normal declared type for a session handle, socreateQuery/createSQLQuerycalled on it is the same sink.Change
Adds
SharedSessionContractnext toSessionin the receiver-type alternatives, for both the local-variable and method-parameter shapes. All the existing guards (the"..." + "..."exclusions, thecreateQuery|createSQLQuerymethod filter) apply unchanged, so a constant query on aSharedSessionContractis still not flagged.The StringBuilder case from the issue is intentionally left out: tracking a query assembled via
StringBuilder.append(...).toString()needs more than a receiver-type addition (and my first attempt at apattern-insidefor it made the rule fail to parse), so it's better handled as a separate change than bundled in loosely here.Tests
hibernate-sqli.javagains atestSharedSessionContractmethod with the reproducer asruleidand a constant query asok.