|
| 1 | +/** |
| 2 | + * Provides classes and predicates for reasoning about hardcoded cryptographic value |
| 3 | + * vulnerabilities. |
| 4 | + */ |
| 5 | + |
| 6 | +import rust |
| 7 | +private import codeql.rust.dataflow.DataFlow |
| 8 | +private import codeql.rust.dataflow.internal.DataFlowImpl |
| 9 | +private import codeql.rust.security.SensitiveData |
| 10 | + |
| 11 | +/** |
| 12 | + * Provides default sources, sinks and barriers for detecting hardcoded cryptographic |
| 13 | + * value vulnerabilities, as well as extension points for adding your own. |
| 14 | + */ |
| 15 | +module HardcodedCryptographicValue { |
| 16 | + /** |
| 17 | + * A data flow source for hardcoded cryptographic value vulnerabilities. |
| 18 | + */ |
| 19 | + abstract class Source extends DataFlow::Node { } |
| 20 | + |
| 21 | + /** |
| 22 | + * A data flow sink for hardcoded cryptographic value vulnerabilities. |
| 23 | + */ |
| 24 | + abstract class Sink extends DataFlow::Node { |
| 25 | + /** |
| 26 | + * Gets the kind of credential this sink is interpreted as, |
| 27 | + * for example "password", "key", "iv", "salt". |
| 28 | + */ |
| 29 | + abstract string getKind(); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * A barrier for hardcoded cryptographic value vulnerabilities. |
| 34 | + */ |
| 35 | + abstract class Barrier extends DataFlow::Node { } |
| 36 | + |
| 37 | + /** |
| 38 | + * A literal, considered as a flow source. |
| 39 | + */ |
| 40 | + private class LiteralSource extends Source { |
| 41 | + LiteralSource() { this.asExpr().getExpr() instanceof LiteralExpr } |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * A sink for hardcoded cryptographic value from model data. |
| 46 | + */ |
| 47 | + private class ModelsAsDataSinks extends Sink { |
| 48 | + string kind; |
| 49 | + |
| 50 | + ModelsAsDataSinks() { |
| 51 | + kind = ["password", "key", "iv", "salt"] and |
| 52 | + sinkNode(this, "credentials-" + kind) |
| 53 | + } |
| 54 | + |
| 55 | + override string getKind() { result = kind } |
| 56 | + } |
| 57 | +} |
0 commit comments