|
| 1 | +/** |
| 2 | + * @name Cleartext storage of sensitive information in a database |
| 3 | + * @description Storing sensitive information in a non-encrypted |
| 4 | + * database can expose it to an attacker. |
| 5 | + * @kind path-problem |
| 6 | + * @problem.severity warning |
| 7 | + * @security-severity 7.5 |
| 8 | + * @precision high |
| 9 | + * @id rust/cleartext-storage-database |
| 10 | + * @tags security |
| 11 | + * external/cwe/cwe-312 |
| 12 | + */ |
| 13 | + |
| 14 | +import rust |
| 15 | +import codeql.rust.dataflow.DataFlow |
| 16 | +import codeql.rust.dataflow.TaintTracking |
| 17 | +import codeql.rust.security.CleartextStorageDatabaseExtensions |
| 18 | + |
| 19 | +/** |
| 20 | + * A taint configuration from sensitive information to expressions that are |
| 21 | + * stored in a database. |
| 22 | + */ |
| 23 | +module CleartextStorageDatabaseConfig implements DataFlow::ConfigSig { |
| 24 | + import CleartextStorageDatabase |
| 25 | + |
| 26 | + predicate isSource(DataFlow::Node node) { node instanceof Source } |
| 27 | + |
| 28 | + predicate isSink(DataFlow::Node node) { node instanceof Sink } |
| 29 | + |
| 30 | + predicate isBarrier(DataFlow::Node barrier) { barrier instanceof Barrier } |
| 31 | + |
| 32 | + predicate isBarrierIn(DataFlow::Node node) { |
| 33 | + // make sources barriers so that we only report the closest instance |
| 34 | + isSource(node) |
| 35 | + } |
| 36 | + |
| 37 | + predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { |
| 38 | + // flow from `a` to `&a` |
| 39 | + node2.asExpr().getExpr().(RefExpr).getExpr() = node1.asExpr().getExpr() |
| 40 | + } |
| 41 | + |
| 42 | + predicate observeDiffInformedIncrementalMode() { any() } |
| 43 | +} |
| 44 | + |
| 45 | +module CleartextStorageDatabaseFlow = TaintTracking::Global<CleartextStorageDatabaseConfig>; |
| 46 | + |
| 47 | +import CleartextStorageDatabaseFlow::PathGraph |
| 48 | + |
| 49 | +from |
| 50 | + CleartextStorageDatabaseFlow::PathNode sourceNode, CleartextStorageDatabaseFlow::PathNode sinkNode |
| 51 | +where CleartextStorageDatabaseFlow::flowPath(sourceNode, sinkNode) |
| 52 | +select sinkNode.getNode(), sourceNode, sinkNode, |
| 53 | + "This database operation may read or write unencrypted sensitive data from $@.", sourceNode, |
| 54 | + sourceNode.getNode().toString() |
0 commit comments