Skip to content

Commit 3efb825

Browse files
committed
feat: update Weak PRNG query
1 parent ff006d0 commit 3efb825

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
private import semmle.python.ApiGraphs
2+
private import semmle.python.Concepts
3+
private import semmle.python.dataflow.new.DataFlow
4+
5+
abstract class RandomNumberGeneratorSinks extends DataFlow::Node { }
6+
7+
class OSRandom extends RandomNumberGeneratorSinks {
8+
OSRandom() {
9+
exists(DataFlow::Node call |
10+
// https://docs.python.org/3/library/os.html#os.getrandom
11+
call = API::moduleImport("os").getMember("getrandom").getACall() and
12+
this = call
13+
)
14+
}
15+
}
16+
17+
class PyRandom extends RandomNumberGeneratorSinks {
18+
PyRandom() {
19+
exists(DataFlow::Node call |
20+
(
21+
// https://docs.python.org/3/library/random.html#random.random
22+
call = API::moduleImport("random").getMember("random").getACall()
23+
or
24+
// https://docs.python.org/3/library/random.html#random.randbytes
25+
call = API::moduleImport("random").getMember("randbytes").getACall()
26+
) and
27+
this = call
28+
)
29+
}
30+
}
31+
32+
class PyUuid extends RandomNumberGeneratorSinks {
33+
PyUuid() {
34+
exists(DataFlow::Node call |
35+
call = API::moduleImport("uuid").getMember("uuid1").getACall() or
36+
call = API::moduleImport("uuid").getMember("uuid3").getACall() and
37+
this = call
38+
)
39+
}
40+
}

python/src/security/CWE-338/WeakPRNG.ql

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,7 @@
1212
*/
1313

1414
import python
15-
import semmle.python.ApiGraphs
16-
17-
abstract class RandomNumberGeneratorSinks extends DataFlow::Node { }
18-
19-
class OSRandom extends RandomNumberGeneratorSinks {
20-
OSRandom() {
21-
exists(DataFlow::Node call |
22-
// https://docs.python.org/3/library/os.html#os.getrandom
23-
call = API::moduleImport("os").getMember("getrandom").getACall() and
24-
this = call
25-
)
26-
}
27-
}
28-
29-
class PyRandom extends RandomNumberGeneratorSinks {
30-
PyRandom() {
31-
exists(DataFlow::Node call |
32-
(
33-
// https://docs.python.org/3/library/random.html#random.random
34-
call = API::moduleImport("random").getMember("random").getACall()
35-
or
36-
// https://docs.python.org/3/library/random.html#random.randbytes
37-
call = API::moduleImport("random").getMember("randbytes").getACall()
38-
) and
39-
this = call
40-
)
41-
}
42-
}
15+
import github.crytography.WeakPRNG
4316

4417
from RandomNumberGeneratorSinks rngs
4518
select rngs.asExpr(), "Using weak PRNG"

0 commit comments

Comments
 (0)