-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathJHipsterGeneratedPRNG.ql
More file actions
51 lines (45 loc) · 1.8 KB
/
JHipsterGeneratedPRNG.ql
File metadata and controls
51 lines (45 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* @name Detect JHipster Generator Vulnerability CVE-2019-16303
* @description Using a vulnerable version of JHipster to generate random numbers makes it easier for attackers to take over accounts.
* @kind problem
* @problem.severity error
* @security-severity 7.8
* @precision very-high
* @id java/jhipster-prng
* @tags security
* external/cwe/cwe-338
*/
import java
import semmle.code.java.frameworks.apache.Lang
private class PredictableApacheRandomStringUtilsMethod extends Method {
PredictableApacheRandomStringUtilsMethod() {
this.getDeclaringType() instanceof TypeApacheRandomStringUtils and
// The one valid use of this type that uses SecureRandom as a source of data.
not this.getName() = "random"
}
}
private class PredictableApacheRandomStringUtilsMethodCall extends MethodCall {
PredictableApacheRandomStringUtilsMethodCall() {
this.getMethod() instanceof PredictableApacheRandomStringUtilsMethod
}
}
private class VulnerableJHipsterRandomUtilClass extends Class {
VulnerableJHipsterRandomUtilClass() {
// The package name that JHipster generated the 'RandomUtil' class in was dynamic. Thus 'hasQualifiedName' can not be used here.
this.getName() = "RandomUtil"
}
}
private class VulnerableJHipsterRandomUtilMethod extends Method {
VulnerableJHipsterRandomUtilMethod() {
this.getDeclaringType() instanceof VulnerableJHipsterRandomUtilClass and
this.getName().matches("generate%") and
this.getReturnType() instanceof TypeString and
exists(ReturnStmt s |
s = this.getBody().(SingletonBlock).getStmt() and
s.getResult() instanceof PredictableApacheRandomStringUtilsMethodCall
)
}
}
from VulnerableJHipsterRandomUtilMethod method
select method,
"Weak random number generator used in security sensitive method (JHipster CVE-2019-16303)."