mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Move class for getProperty method call to Properties.qll
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
import semmle.code.java.Type
|
||||
private import semmle.code.java.dataflow.FlowSteps
|
||||
private import semmle.code.configfiles.ConfigFiles
|
||||
private import semmle.code.java.dataflow.RangeUtils
|
||||
|
||||
/**
|
||||
* The `java.util.Properties` class.
|
||||
@@ -43,3 +45,19 @@ class PropertiesStoreMethod extends Method {
|
||||
(this.getName().matches("store%") or this.getName() = "save")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A call to the `getProperty` method of the class `java.util.Properties`.
|
||||
*/
|
||||
class PropertiesGetPropertyMethodCall extends MethodCall {
|
||||
PropertiesGetPropertyMethodCall() { this.getMethod() instanceof PropertiesGetPropertyMethod }
|
||||
|
||||
private ConfigPair getPair() {
|
||||
this.getArgument(0).(ConstantStringExpr).getStringValue() = result.getNameElement().getName()
|
||||
}
|
||||
|
||||
string getPropertyValue() {
|
||||
result = this.getPair().getValueElement().getValue() or
|
||||
result = this.getArgument(1).(ConstantStringExpr).getStringValue()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,31 +37,6 @@ private predicate objectToString(MethodCall ma) {
|
||||
)
|
||||
}
|
||||
|
||||
private class GetPropertyMethodCall extends MethodCall {
|
||||
GetPropertyMethodCall() { this.getMethod() instanceof PropertiesGetPropertyMethod }
|
||||
|
||||
private ConfigPair getPair() {
|
||||
this.getArgument(0).(ConstantStringExpr).getStringValue() = result.getNameElement().getName()
|
||||
}
|
||||
|
||||
string getPropertyValue() {
|
||||
result = this.getPair().getValueElement().getValue() or
|
||||
result = this.getArgument(1).(ConstantStringExpr).getStringValue()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string value represented by the given expression.
|
||||
*
|
||||
* If the value is a string literal, return the literal value.
|
||||
* If the value is a call to `java.util.Properties::getProperty`, return the potential values of the property.
|
||||
*/
|
||||
string insecureAlgorithmName(DataFlow::Node algo) {
|
||||
result = algo.asExpr().(StringLiteral).getValue()
|
||||
or
|
||||
result = algo.asExpr().(GetPropertyMethodCall).getPropertyValue()
|
||||
}
|
||||
|
||||
/**
|
||||
* A taint-tracking configuration to reason about the use of potentially insecure cryptographic algorithms.
|
||||
*/
|
||||
@@ -69,7 +44,7 @@ module InsecureCryptoConfig implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node n) {
|
||||
n.asExpr() instanceof InsecureAlgoLiteral
|
||||
or
|
||||
exists(GetPropertyMethodCall mc | n.asExpr() = mc |
|
||||
exists(PropertiesGetPropertyMethodCall mc | n.asExpr() = mc |
|
||||
// Since properties pairs are not included in the java/weak-crypto-algorithm,
|
||||
// The check for values from properties files can be less strict than `InsecureAlgoLiteral`.
|
||||
not mc.getPropertyValue().regexpMatch(getSecureAlgorithmRegex())
|
||||
|
||||
Reference in New Issue
Block a user