|
1 | 1 | /** |
2 | | - * LogSanitizer.ql |
3 | | - * |
4 | | - * Filter/suppress log-injection findings when the taint flow can be shown to |
5 | | - * pass through a sanitizer (including zap custom encoders). |
6 | | - * |
7 | | - * NOTE: This is a conservative template. Integrate with your existing |
8 | | - * taint-tracking / source/sink predicates used by your log-injection rules. |
| 2 | + * @name Log entries created from user input |
| 3 | + * @description Building log entries from user-controlled sources is vulnerable to |
| 4 | + * insertion of forged log entries by a malicious user. |
| 5 | + * @kind path-problem |
| 6 | + * @problem.severity error |
| 7 | + * @id go/log-injection |
| 8 | + * @tags security |
| 9 | + * experimental |
| 10 | + * external/cwe/cwe-287 |
9 | 11 | */ |
10 | 12 |
|
| 13 | +import go |
| 14 | +import semmle.go.security.LogInjection |
| 15 | +import LogInjection::Flow::PathGraph |
| 16 | + |
| 17 | +from LogInjection::Flow::PathNode source, LogInjection::Flow::PathNode sink |
| 18 | +where LogInjection::Flow::flowPath(source, sink) |
| 19 | +select sink.getNode(), source, sink, "This log entry depends on a $@.", source.getNode(), |
| 20 | + "user-provided value" |
| 21 | + |
11 | 22 | import go |
12 | 23 | import go.security.dataflow.TaintTracking as T |
13 | | -// adjust imports above if your repo uses a different taint package |
14 | 24 |
|
15 | | -// Reuse the library predicates |
16 | 25 | import LogSanitizer |
17 | 26 |
|
18 | | -/** |
19 | | - * A wrapper sink used for demonstration. Replace with the actual log sink |
20 | | - * definitions used by your log-injection query if you want precise suppression. |
21 | | - */ |
22 | 27 | class LogSink extends T.Sink { |
23 | 28 | LogSink() { this = T.Sink("LogSink") } |
24 | 29 | } |
25 | 30 |
|
26 | | -/** |
27 | | - * Find flows from sources to log sinks but ignore flows that pass through a sanitizer. |
28 | | - * This query demonstrates the pattern — adapt to concrete source/sink definitions. |
29 | | - */ |
30 | 31 | from T.Source src, T.Sink sink, Function sanitizerFn |
31 | 32 | where |
32 | 33 | src.flowsTo(sink) and |
33 | 34 | not exists(sanitizerFn | |
34 | 35 | isSanitizer(sanitizerFn) and |
35 | | - // sanitizer function appears somewhere on the flow path |
36 | 36 | src.flowsTo(sanitizerFn) and |
37 | 37 | sanitizerFn.flowsTo(sink) |
38 | 38 | ) |
|
0 commit comments