mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
Add TaintedPermissionsCheckQuery
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* Added the `TaintedPermissionQuery.qll` library to provide the `TaintedPermissionFlow` taint-tracking module to reason about tainted permission vulnerabilities.
|
||||
@@ -0,0 +1,65 @@
|
||||
/** Provides classes to reason about tainted permissions check vulnerabilities. */
|
||||
|
||||
import java
|
||||
import semmle.code.java.dataflow.FlowSources
|
||||
import semmle.code.java.dataflow.TaintTracking
|
||||
|
||||
/**
|
||||
* The `org.apache.shiro.subject.Subject` class.
|
||||
*/
|
||||
private class TypeShiroSubject extends RefType {
|
||||
TypeShiroSubject() { this.getQualifiedName() = "org.apache.shiro.subject.Subject" }
|
||||
}
|
||||
|
||||
/**
|
||||
* The `org.apache.shiro.authz.permission.WildcardPermission` class.
|
||||
*/
|
||||
private class TypeShiroWildCardPermission extends RefType {
|
||||
TypeShiroWildCardPermission() {
|
||||
this.getQualifiedName() = "org.apache.shiro.authz.permission.WildcardPermission"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An expression that constructs a permission.
|
||||
*/
|
||||
abstract class PermissionsConstruction extends Top {
|
||||
/** Gets the input to this permission construction. */
|
||||
abstract Expr getInput();
|
||||
}
|
||||
|
||||
private class PermissionsCheckMethodAccess extends MethodAccess, PermissionsConstruction {
|
||||
PermissionsCheckMethodAccess() {
|
||||
exists(Method m | m = this.getMethod() |
|
||||
m.getDeclaringType() instanceof TypeShiroSubject and
|
||||
m.getName() = "isPermitted"
|
||||
or
|
||||
m.getName().toLowerCase().matches("%permitted%") and
|
||||
m.getNumberOfParameters() = 1
|
||||
)
|
||||
}
|
||||
|
||||
override Expr getInput() { result = this.getArgument(0) }
|
||||
}
|
||||
|
||||
private class WildCardPermissionConstruction extends ClassInstanceExpr, PermissionsConstruction {
|
||||
WildCardPermissionConstruction() {
|
||||
this.getConstructor().getDeclaringType() instanceof TypeShiroWildCardPermission
|
||||
}
|
||||
|
||||
override Expr getInput() { result = this.getArgument(0) }
|
||||
}
|
||||
|
||||
/**
|
||||
* A configuration for tracking flow from user input to a permissions check.
|
||||
*/
|
||||
module TaintedPermissionsCheckFlowConfig implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node source) { source instanceof UserInput }
|
||||
|
||||
predicate isSink(DataFlow::Node sink) {
|
||||
sink.asExpr() = any(PermissionsConstruction p).getInput()
|
||||
}
|
||||
}
|
||||
|
||||
/** Tracks flow from user input to a permissions check. */
|
||||
module TaintedPermissionsCheckFlow = TaintTracking::Global<TaintedPermissionsCheckFlowConfig>;
|
||||
Reference in New Issue
Block a user