Skip to content

Commit 123214c

Browse files
Promoto cookie injection query
1 parent bf4a202 commit 123214c

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Provides default sources, sinks and sanitizers for detecting
3+
* "cookie injection"
4+
* vulnerabilities, as well as extension points for adding your own.
5+
*/
6+
7+
private import python
8+
private import semmle.python.dataflow.new.DataFlow
9+
private import semmle.python.Concepts
10+
private import semmle.python.dataflow.new.RemoteFlowSources
11+
12+
/**
13+
* Provides default sources, sinks and sanitizers for detecting
14+
* "cookie injection"
15+
* vulnerabilities, as well as extension points for adding your own.
16+
*/
17+
module CookieInjection {
18+
/**
19+
* A data flow source for "cookie injection" vulnerabilities.
20+
*/
21+
abstract class Source extends DataFlow::Node { }
22+
23+
/**
24+
* A data flow sink for "cookie injection" vulnerabilities.
25+
*/
26+
abstract class Sink extends DataFlow::Node { }
27+
28+
/**
29+
* A sanitizer for "cookie injection" vulnerabilities.
30+
*/
31+
abstract class Sanitizer extends DataFlow::Node { }
32+
33+
/**
34+
* A source of remote user input, considered as a flow source.
35+
*/
36+
class RemoteFlowSourceAsSource extends Source, RemoteFlowSource { }
37+
38+
/**
39+
* A write to a cookie, considered as a sink.
40+
*/
41+
class CookieWriteSink extends Sink {
42+
CookieWriteSink() {
43+
exists(Http::Server::CookieWrite cw |
44+
this = [cw.getNameArg(), cw.getValueArg(), cw.getHeaderArg()]
45+
)
46+
}
47+
}
48+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Provides a taint-tracking configuration for detecting "cookie injection" vulnerabilities.
3+
*
4+
* Note, for performance reasons: only import this file if
5+
* `CookieInjectionFlow` is needed, otherwise
6+
* `CookieInjectionCustomizations` should be imported instead.
7+
*/
8+
9+
private import python
10+
import semmle.python.dataflow.new.DataFlow
11+
import semmle.python.dataflow.new.TaintTracking
12+
import CookieInjectionCustomizations::CookieInjection
13+
14+
/**
15+
* A taint-tracking configuration for detecting "cookie injection" vulnerabilities.
16+
*/
17+
module CookieInjectionConfig implements DataFlow::ConfigSig {
18+
predicate isSource(DataFlow::Node source) { source instanceof Source }
19+
20+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
21+
22+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
23+
}
24+
25+
/** Global taint-tracking for detecting "cookie injection" vulnerabilities. */
26+
module CookieInjectionFlow = TaintTracking::Global<CookieInjectionConfig>;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @name Construction of a cookie using user-supplied input.
3+
* @description Constructing cookies from user input may allow an attacker to perform a Cookie Poisoning attack.
4+
* @kind path-problem
5+
* @problem.severity error
6+
* @precision high
7+
* @id py/cookie-injection
8+
* @tags security
9+
* external/cwe/cwe-614
10+
*/
11+
12+
import python
13+
import semmle.python.dataflow.new.DataFlow
14+
import semmle.python.security.dataflow.CookieInjectionQuery
15+
import CookieInjectionFlow::PathGraph
16+
17+
from CookieInjectionFlow::PathNode source, CookieInjectionFlow::PathNode sink
18+
where CookieInjectionFlow::flowPath(source, sink)
19+
select sink.getNode(), source, sink, "Cookie is constructed from a $@.", source.getNode(),
20+
"user-supplied input"

0 commit comments

Comments
 (0)