Skip to content

Commit 0cadf4d

Browse files
authored
Merge pull request github#12558 from smowton/smowton/fix/flow-to-external-api-write-only-methods
Go: exclude `net/http.Header.Set` and `.Del` from `go/untrusted-data-to-external-api`
2 parents b8fb4b9 + 3e9924f commit 0cadf4d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

go/ql/lib/semmle/go/security/ExternalAPIs.qll

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ abstract class SafeExternalApiFunction extends Function { }
1919
/** DEPRECATED: Alias for SafeExternalApiFunction */
2020
deprecated class SafeExternalAPIFunction = SafeExternalApiFunction;
2121

22+
/**
23+
* A `Function` with one or more arguments that are considered "safe" from a security perspective.
24+
*/
25+
abstract class SafeExternalApiArgument extends Function {
26+
/**
27+
* Holds if `i` is a safe argument to this function.
28+
*/
29+
abstract predicate isSafeArgument(int i);
30+
}
31+
2232
private predicate isDefaultSafePackage(Package package) {
2333
package.getPath() in ["time", "unicode/utf8", package("gopkg.in/go-playground/validator", "")]
2434
}
@@ -44,6 +54,16 @@ private class DefaultSafeExternalApiFunction extends SafeExternalApiFunction {
4454
}
4555
}
4656

57+
private class DefaultSafeExternalApiFunctionArgument extends SafeExternalApiArgument {
58+
int index;
59+
60+
DefaultSafeExternalApiFunctionArgument() {
61+
this.(Method).hasQualifiedName("net/http", "Header", ["Set", "Del"]) and index = -1
62+
}
63+
64+
override predicate isSafeArgument(int i) { i = index }
65+
}
66+
4767
/** Holds if `callNode` is a local function pointer. */
4868
private predicate isProbableLocalFunctionPointer(DataFlow::CallNode callNode) {
4969
// Not a method call
@@ -77,7 +97,9 @@ class ExternalApiDataNode extends DataFlow::Node {
7797
// Not already modeled as a taint step
7898
not TaintTracking::localTaintStep(this, _) and
7999
// Not a call to a known safe external API
80-
not call.getTarget() instanceof SafeExternalApiFunction
100+
not call.getTarget() instanceof SafeExternalApiFunction and
101+
// Not a known safe argument to an external API
102+
not any(SafeExternalApiArgument seaa).isSafeArgument(i)
81103
}
82104

83105
/** Gets the called API `Function`. */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The receiver arguments of `net/http.Header.Set` and `.Del` are no longer flagged by query `go/untrusted-data-to-external-api`.

0 commit comments

Comments
 (0)