|
| 1 | +/** |
| 2 | + * Provides default sources, sinks, and sanitizers for reasoning about random values that |
| 3 | + * are not cryptographically secure, as well as extension points for adding your own. |
| 4 | + */ |
| 5 | + |
| 6 | +private import codeql.ruby.CFG |
| 7 | +private import codeql.ruby.AST |
| 8 | +private import codeql.ruby.DataFlow |
| 9 | +private import codeql.ruby.security.SensitiveActions |
| 10 | +private import codeql.ruby.Concepts |
| 11 | +private import codeql.ruby.ApiGraphs |
| 12 | +import codeql.ruby.frameworks.core.Kernel |
| 13 | + |
| 14 | +/** |
| 15 | + * Provides default sources, sinks, and sanitizers for reasoning about random values that |
| 16 | + * are not cryptographically secure, as well as extension points for adding your own. |
| 17 | + */ |
| 18 | +module InsecureRandomness { |
| 19 | + /** |
| 20 | + * A data flow source for random values that are not cryptographically secure. |
| 21 | + */ |
| 22 | + abstract class Source extends DataFlow::Node { } |
| 23 | + |
| 24 | + /** |
| 25 | + * A data flow sink for random values that are not cryptographically secure. |
| 26 | + */ |
| 27 | + abstract class Sink extends DataFlow::Node { } |
| 28 | + |
| 29 | + /** |
| 30 | + * A sanitizer for random values that are not cryptographically secure. |
| 31 | + */ |
| 32 | + abstract class Sanitizer extends DataFlow::Node { } |
| 33 | + |
| 34 | + /** |
| 35 | + * A simple random number generator that is not cryptographically secure. |
| 36 | + */ |
| 37 | + class DefaultSource extends Source, DataFlow::CallNode { |
| 38 | + DefaultSource() { |
| 39 | + this.asExpr().getExpr() instanceof UnknownMethodCall and |
| 40 | + ( |
| 41 | + this.getReceiver().asExpr().getExpr() instanceof SelfVariableAccess and |
| 42 | + super.getMethodName() = "rand" |
| 43 | + ) |
| 44 | + or |
| 45 | + this.(Kernel::KernelMethodCall).getMethodName() = "rand" |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * A sensitive write, considered as a sink for random values that are not cryptographically |
| 51 | + * secure. |
| 52 | + */ |
| 53 | + class SensitiveWriteSink extends Sink instanceof SensitiveWrite { } |
| 54 | + |
| 55 | + /** |
| 56 | + * A cryptographic key, considered as a sink for random values that are not cryptographically |
| 57 | + * secure. |
| 58 | + */ |
| 59 | + class CryptoKeySink extends Sink { |
| 60 | + CryptoKeySink() { |
| 61 | + exists(Cryptography::CryptographicOperation operation | this = operation.getAnInput()) |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * A index call, considered as a sink for random values that are not cryptographiocally |
| 67 | + * secure |
| 68 | + */ |
| 69 | + class CharacterIndexing extends Sink { |
| 70 | + CharacterIndexing() { |
| 71 | + exists(DataFlow::CallNode c | this = c.getAMethodCall("[]").getArgument(0)) |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments