|
9 | 9 | * external/cwe/cwe-312
|
10 | 10 | */
|
11 | 11 |
|
| 12 | + |
12 | 13 | import cpp
|
13 | 14 | import semmle.code.cpp.security.BufferWrite
|
14 |
| -import semmle.code.cpp.security.TaintTracking |
15 | 15 | import experimental.semmle.code.cpp.security.PrivateData
|
16 |
| -import TaintedWithPath |
| 16 | +import semmle.code.cpp.dataflow.TaintTracking |
| 17 | + |
| 18 | +/** A call to any method whose name suggests that it encodes or encrypts the parameter. */ |
| 19 | +class ProtectSanitizer extends DataFlow::ExprNode { |
| 20 | + ProtectSanitizer() { |
| 21 | + exists(Function m, string s | |
| 22 | + this.getExpr().(FunctionCall).getTarget() = m and |
| 23 | + m.getName().regexpMatch("(?i).*" + s + ".*") |
| 24 | + | |
| 25 | + s = "protect" or s = "encode" or s = "encrypt" |
| 26 | + ) |
| 27 | + } |
| 28 | +} |
17 | 29 |
|
18 |
| -class Configuration extends TaintTrackingConfiguration { |
19 |
| - override predicate isSink(Element tainted) { exists(BufferWrite w | w.getASource() = tainted) } |
| 30 | +class BufferConfig extends TaintTracking::Configuration { |
| 31 | + BufferConfig() { |
| 32 | + this = "Buffer store configuration" |
| 33 | + } |
| 34 | + override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof PrivateDataExpr } |
| 35 | + override predicate isSink(DataFlow::Node sink) { exists(BufferWrite w | sink.asExpr() = w.getDest()) } |
| 36 | + override predicate isSanitizer(DataFlow::Node node) { node instanceof ProtectSanitizer } |
20 | 37 | }
|
21 | 38 |
|
22 | 39 | from
|
23 |
| - BufferWrite w, Expr taintedArg, Expr taintSource, PathNode sourceNode, PathNode sinkNode, |
24 |
| - string taintCause, PrivateDataExpr dest |
| 40 | + BufferWrite w, BufferConfig b, Expr taintedArg, DataFlow::Node source, DataFlow::Node sink |
25 | 41 | where
|
26 |
| - taintedWithPath(taintSource, taintedArg, sourceNode, sinkNode) and |
27 |
| - isUserInput(taintSource, taintCause) and |
28 |
| - w.getASource() = taintedArg and |
29 |
| - dest = w.getDest() |
30 |
| -select w, sourceNode, sinkNode, |
31 |
| - "This write into buffer '" + dest.toString() + "' may contain unencrypted data from $@", |
32 |
| - taintSource, "user input (" + taintCause + ")" |
| 42 | + b.hasFlow(source, sink) and |
| 43 | + w.getASource() = taintedArg |
| 44 | +select w, source, sink, "This write into this buffer may contain unencrypted data" |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +// import cpp |
| 50 | +// import semmle.code.cpp.security.BufferWrite |
| 51 | +// import semmle.code.cpp.security.TaintTracking |
| 52 | +// import experimental.semmle.code.cpp.security.PrivateData |
| 53 | +// import TaintedWithPath |
| 54 | + |
| 55 | +// class Configuration extends TaintTrackingConfiguration { |
| 56 | +// override predicate isSink(Element tainted) { exists(BufferWrite w | w.getASource() = tainted) } |
| 57 | +// } |
| 58 | + |
| 59 | +// from |
| 60 | +// BufferWrite w, Expr taintedArg, Expr taintSource, PathNode sourceNode, PathNode sinkNode, |
| 61 | +// string taintCause, PrivateDataExpr dest |
| 62 | +// where |
| 63 | +// taintedWithPath(taintSource, taintedArg, sourceNode, sinkNode) and |
| 64 | +// isUserInput(taintSource, taintCause) and |
| 65 | +// w.getASource() = taintedArg and |
| 66 | +// dest = w.getDest() |
| 67 | +// select w, sourceNode, sinkNode, |
| 68 | +// "This write into buffer '" + dest.toString() + "' may contain unencrypted data from $@", |
| 69 | +// taintSource, "user input (" + taintCause + ")" |
0 commit comments