Skip to content

Commit 647bd44

Browse files
committed
Go: exclude net/http.Header.Set and .Del from go/untrusted-data-to-external-api
These functions (and doubtless many others) are write-only with respect to their receiver argument, so it doesn't really make sense to flag externally-controlled data flowing there.
1 parent a9e5b34 commit 647bd44

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-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`. */

0 commit comments

Comments
 (0)