mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
Java: Generelize MaybeBrokenCryptoAlgorithmQuery.qll
This commit is contained in:
@@ -18,24 +18,10 @@ import semmle.code.java.frameworks.Properties
|
||||
import semmle.code.java.security.MaybeBrokenCryptoAlgorithmQuery
|
||||
import InsecureCryptoFlow::PathGraph
|
||||
|
||||
/**
|
||||
* Get the string value represented by the given expression.
|
||||
*
|
||||
* If the value is a string literal, get the literal value.
|
||||
* If the value is a call to `java.util.Properties::getProperty`, get the potential values of the property.
|
||||
*/
|
||||
string getStringValue(DataFlow::Node algo) {
|
||||
result = algo.asExpr().(StringLiteral).getValue()
|
||||
or
|
||||
exists(string value | value = algo.asExpr().(PropertiesGetPropertyMethodCall).getPropertyValue() |
|
||||
result = value and not value.regexpMatch(getSecureAlgorithmRegex())
|
||||
)
|
||||
}
|
||||
|
||||
from InsecureCryptoFlow::PathNode source, InsecureCryptoFlow::PathNode sink, CryptoAlgoSpec c
|
||||
where
|
||||
sink.getNode().asExpr() = c.getAlgoSpec() and
|
||||
InsecureCryptoFlow::flowPath(source, sink)
|
||||
select c, source, sink,
|
||||
"Cryptographic algorithm $@ may not be secure, consider using a different algorithm.", source,
|
||||
getStringValue(source.getNode())
|
||||
source.getNode().asExpr().(InsecureAlgorithm).getStringValue()
|
||||
|
||||
Reference in New Issue
Block a user