File tree Expand file tree Collapse file tree 2 files changed +41
-28
lines changed
Expand file tree Collapse file tree 2 files changed +41
-28
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1212 */
1313
1414import 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
4417from RandomNumberGeneratorSinks rngs
4518select rngs .asExpr ( ) , "Using weak PRNG"
You can’t perform that action at this time.
0 commit comments