Skip to content

Commit 1af6d5f

Browse files
committed
Add TaintedPermissionsCheckQuery
1 parent 4035b16 commit 1af6d5f

File tree

3 files changed

+70
-49
lines changed

3 files changed

+70
-49
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added the `TaintedPermissionQuery.qll` library to provide the `TaintedPermissionFlow` taint-tracking module to reason about tainted permission vulnerabilities.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/** Provides classes to reason about tainted permissions check vulnerabilities. */
2+
3+
import java
4+
import semmle.code.java.dataflow.FlowSources
5+
import semmle.code.java.dataflow.TaintTracking
6+
7+
/**
8+
* The `org.apache.shiro.subject.Subject` class.
9+
*/
10+
private class TypeShiroSubject extends RefType {
11+
TypeShiroSubject() { this.getQualifiedName() = "org.apache.shiro.subject.Subject" }
12+
}
13+
14+
/**
15+
* The `org.apache.shiro.authz.permission.WildcardPermission` class.
16+
*/
17+
private class TypeShiroWildCardPermission extends RefType {
18+
TypeShiroWildCardPermission() {
19+
this.getQualifiedName() = "org.apache.shiro.authz.permission.WildcardPermission"
20+
}
21+
}
22+
23+
/**
24+
* An expression that constructs a permission.
25+
*/
26+
abstract class PermissionsConstruction extends Top {
27+
/** Gets the input to this permission construction. */
28+
abstract Expr getInput();
29+
}
30+
31+
private class PermissionsCheckMethodAccess extends MethodAccess, PermissionsConstruction {
32+
PermissionsCheckMethodAccess() {
33+
exists(Method m | m = this.getMethod() |
34+
m.getDeclaringType() instanceof TypeShiroSubject and
35+
m.getName() = "isPermitted"
36+
or
37+
m.getName().toLowerCase().matches("%permitted%") and
38+
m.getNumberOfParameters() = 1
39+
)
40+
}
41+
42+
override Expr getInput() { result = this.getArgument(0) }
43+
}
44+
45+
private class WildCardPermissionConstruction extends ClassInstanceExpr, PermissionsConstruction {
46+
WildCardPermissionConstruction() {
47+
this.getConstructor().getDeclaringType() instanceof TypeShiroWildCardPermission
48+
}
49+
50+
override Expr getInput() { result = this.getArgument(0) }
51+
}
52+
53+
/**
54+
* A configuration for tracking flow from user input to a permissions check.
55+
*/
56+
module TaintedPermissionsCheckFlowConfig implements DataFlow::ConfigSig {
57+
predicate isSource(DataFlow::Node source) { source instanceof UserInput }
58+
59+
predicate isSink(DataFlow::Node sink) {
60+
sink.asExpr() = any(PermissionsConstruction p).getInput()
61+
}
62+
}
63+
64+
/** Tracks flow from user input to a permissions check. */
65+
module TaintedPermissionsCheckFlow = TaintTracking::Global<TaintedPermissionsCheckFlowConfig>;

java/ql/src/Security/CWE/CWE-807/TaintedPermissionsCheck.ql

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,7 @@
1313
*/
1414

1515
import java
16-
import semmle.code.java.dataflow.FlowSources
17-
import semmle.code.java.dataflow.TaintTracking
18-
19-
class TypeShiroSubject extends RefType {
20-
TypeShiroSubject() { this.getQualifiedName() = "org.apache.shiro.subject.Subject" }
21-
}
22-
23-
class TypeShiroWCPermission extends RefType {
24-
TypeShiroWCPermission() {
25-
this.getQualifiedName() = "org.apache.shiro.authz.permission.WildcardPermission"
26-
}
27-
}
28-
29-
abstract class PermissionsConstruction extends Top {
30-
abstract Expr getInput();
31-
}
32-
33-
class PermissionsCheckMethodAccess extends MethodAccess, PermissionsConstruction {
34-
PermissionsCheckMethodAccess() {
35-
exists(Method m | m = this.getMethod() |
36-
m.getDeclaringType() instanceof TypeShiroSubject and
37-
m.getName() = "isPermitted"
38-
or
39-
m.getName().toLowerCase().matches("%permitted%") and
40-
m.getNumberOfParameters() = 1
41-
)
42-
}
43-
44-
override Expr getInput() { result = this.getArgument(0) }
45-
}
46-
47-
class WCPermissionConstruction extends ClassInstanceExpr, PermissionsConstruction {
48-
WCPermissionConstruction() {
49-
this.getConstructor().getDeclaringType() instanceof TypeShiroWCPermission
50-
}
51-
52-
override Expr getInput() { result = this.getArgument(0) }
53-
}
54-
55-
module TaintedPermissionsCheckFlowConfig implements DataFlow::ConfigSig {
56-
predicate isSource(DataFlow::Node source) { source instanceof UserInput }
57-
58-
predicate isSink(DataFlow::Node sink) {
59-
sink.asExpr() = any(PermissionsConstruction p).getInput()
60-
}
61-
}
62-
63-
module TaintedPermissionsCheckFlow = TaintTracking::Global<TaintedPermissionsCheckFlowConfig>;
64-
16+
import semmle.code.java.security.TaintedPermissionsCheckQuery
6517
import TaintedPermissionsCheckFlow::PathGraph
6618

6719
from

0 commit comments

Comments
 (0)