Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions java/lang/security/audit/sqli/hibernate-sqli.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SharedSessionContract;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.hibernate.type.StandardBasicTypes;
Expand Down Expand Up @@ -43,4 +44,14 @@ public void testQueries(SessionFactory sessionFactory, String input) {
criteria.add(Restrictions.sqlRestriction("param1 = ? and param2 = ?", new String[] {input}, new Type[] {StandardBasicTypes.STRING}));

}

public void testSharedSessionContract(SessionFactory sessionFactory, String input) {
SharedSessionContract session = sessionFactory.openSession();
String hql = "from UserEntity where name = '" + input + "'";
// ruleid: hibernate-sqli
session.createQuery(hql);

// ok: hibernate-sqli
session.createQuery("from UserEntity");
}
}
7 changes: 7 additions & 0 deletions java/lang/security/audit/sqli/hibernate-sqli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ rules:
- pattern-inside: |
org.hibernate.Session $SESSION = ...;
...
- pattern-inside: |
org.hibernate.SharedSessionContract $SESSION = ...;
...
- pattern-inside: |
$TYPE $FUNC(...,org.hibernate.Session $SESSION,...) {
...
}
- pattern-inside: |
$TYPE $FUNC(...,org.hibernate.SharedSessionContract $SESSION,...) {
...
}
- pattern-not: |
$SESSION.$METHOD("..." + "...",...);
- metavariable-regex:
Expand Down