Skip to content

Commit e290802

Browse files
committed
Remove redundancy
1 parent 1ba39e4 commit e290802

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

javascript/ql/src/experimental/Security/CWE-614/InsecureCookie.qll

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,17 @@ module InsecureCookie {
3636
*/
3737
class InsecureCookieSession extends ExpressLibraries::CookieSession::MiddlewareInstance,
3838
InsecureCookies {
39-
InsecureCookieSession() { this instanceof ExpressLibraries::CookieSession::MiddlewareInstance }
40-
4139
override string getKind() { result = "cookie-session" }
4240

43-
override DataFlow::SourceNode getCookieOptionsArgument() {
44-
result = this.getOption("cookie")
45-
}
41+
override DataFlow::SourceNode getCookieOptionsArgument() { result = this.getOption("cookie") }
4642

4743
private DataFlow::Node getCookieFlagValue(string flag) {
4844
result = this.getCookieOptionsArgument().getAPropertyWrite(flag).getRhs()
4945
}
5046

51-
override predicate isInsecure() {
52-
// A cookie is insecure if the `secure` flag is explicitly set to `false`.
53-
getCookieFlagValue(flag()).mayHaveBooleanValue(false)
47+
override predicate isInsecure() {
48+
// A cookie is insecure if the `secure` flag is explicitly set to `false`.
49+
getCookieFlagValue(flag()).mayHaveBooleanValue(false)
5450
}
5551
}
5652

@@ -61,16 +57,14 @@ module InsecureCookie {
6157
InsecureCookies {
6258
override string getKind() { result = "express-session" }
6359

64-
override DataFlow::SourceNode getCookieOptionsArgument() {
65-
result = this.getOption("cookie")
66-
}
60+
override DataFlow::SourceNode getCookieOptionsArgument() { result = this.getOption("cookie") }
6761

6862
private DataFlow::Node getCookieFlagValue(string flag) {
6963
result = this.getCookieOptionsArgument().getAPropertyWrite(flag).getRhs()
7064
}
7165

7266
override predicate isInsecure() {
73-
// A cookie is insecure if there are not cookie options with the `secure` flag set to `true`.
67+
// A cookie is insecure if there are not cookie options with the `secure` flag set to `true`.
7468
not getCookieFlagValue(flag()).mayHaveBooleanValue(true) and
7569
not getCookieFlagValue(flag()).mayHaveStringValue("auto")
7670
}
@@ -95,9 +89,8 @@ module InsecureCookie {
9589
}
9690

9791
override predicate isInsecure() {
98-
// A cookie is insecure if there are not cookie options with the `secure` flag set to `true`.
99-
100-
not getCookieFlagValue(flag()).mayHaveBooleanValue(true)
92+
// A cookie is insecure if there are not cookie options with the `secure` flag set to `true`.
93+
not getCookieFlagValue(flag()).mayHaveBooleanValue(true)
10194
}
10295
}
10396

@@ -116,7 +109,7 @@ module InsecureCookie {
116109
}
117110

118111
override predicate isInsecure() {
119-
// A cookie is insecure if the 'secure' flag is not specified in the cookie definition.
112+
// A cookie is insecure if the 'secure' flag is not specified in the cookie definition.
120113
not exists(string s |
121114
getCookieOptionsArgument().mayHaveStringValue(s) and
122115
s.matches("%; secure%")
@@ -145,7 +138,7 @@ module InsecureCookie {
145138
}
146139

147140
override predicate isInsecure() {
148-
// A cookie is insecure if there are not cookie options with the `secure` flag set to `true`.
141+
// A cookie is insecure if there are not cookie options with the `secure` flag set to `true`.
149142
not getCookieFlagValue(flag()).mayHaveBooleanValue(true)
150143
}
151144
}

0 commit comments

Comments
 (0)