Skip to content

Commit 840cded

Browse files
committed
Avoid using Str_ in CookieHeader
1 parent a4204cc commit 840cded

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

python/ql/src/experimental/semmle/python/CookieHeader.qll

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,39 @@ import experimental.semmle.python.Concepts
2929
class CookieHeader extends Cookie::Range instanceof HeaderDeclaration {
3030
CookieHeader() {
3131
this instanceof HeaderDeclaration and
32-
this.(HeaderDeclaration).getNameArg().asExpr().(Str_).getS() = "Set-Cookie"
32+
exists(StrConst str |
33+
str.getText() = "Set-Cookie" and
34+
DataFlow::exprNode(str)
35+
.(DataFlow::LocalSourceNode)
36+
.flowsTo(this.(HeaderDeclaration).getNameArg())
37+
)
3338
}
3439

3540
override predicate isSecure() {
36-
this.(HeaderDeclaration).getValueArg().asExpr().(Str_).getS().regexpMatch(".*; *Secure;.*")
41+
exists(StrConst str |
42+
str.getText().regexpMatch(".*; *Secure;.*") and
43+
DataFlow::exprNode(str)
44+
.(DataFlow::LocalSourceNode)
45+
.flowsTo(this.(HeaderDeclaration).getValueArg())
46+
)
3747
}
3848

3949
override predicate isHttpOnly() {
40-
this.(HeaderDeclaration).getValueArg().asExpr().(Str_).getS().regexpMatch(".*; *HttpOnly;.*")
50+
exists(StrConst str |
51+
str.getText().regexpMatch(".*; *HttpOnly;.*") and
52+
DataFlow::exprNode(str)
53+
.(DataFlow::LocalSourceNode)
54+
.flowsTo(this.(HeaderDeclaration).getValueArg())
55+
)
4156
}
4257

4358
override predicate isSameSite() {
44-
this.(HeaderDeclaration)
45-
.getValueArg()
46-
.asExpr()
47-
.(Str_)
48-
.getS()
49-
.regexpMatch(".*; *SameSite=(Strict|Lax);.*")
59+
exists(StrConst str |
60+
str.getText().regexpMatch(".*; *SameSite=(Strict|Lax);.*") and
61+
DataFlow::exprNode(str)
62+
.(DataFlow::LocalSourceNode)
63+
.flowsTo(this.(HeaderDeclaration).getValueArg())
64+
)
5065
}
5166

5267
override DataFlow::Node getNameArg() { result = this.(HeaderDeclaration).getValueArg() }

0 commit comments

Comments
 (0)