Skip to content

Commit f18c163

Browse files
committed
Improve handling of the 'author' word as an exception
1 parent 21079a1 commit f18c163

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

java/ql/lib/semmle/code/java/security/SensitiveActions.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class AuthMethod extends SensitiveExecutionMethod {
8181
AuthMethod() {
8282
exists(string s | s = this.getName().toLowerCase() |
8383
s.matches(["%login%", "%auth%"]) and
84-
not s.matches([
85-
"get%", "set%", "parse%", "%loginfo%", "remove%", "clean%", "%unauth%", "%author%"
86-
])
84+
not s.matches(["get%", "set%", "parse%", "%loginfo%", "remove%", "clean%", "%unauth%"]) and
85+
// exclude "author", but not "authorize" or "authority"
86+
not s.regexpMatch(".*[aA]uthors?([A-Z0-9_].*|$)")
8787
) and
8888
not this.getDeclaringType().getASupertype*() instanceof TypeException
8989
}

java/ql/test/query-tests/security/CWE-807/semmle/tests/ConditionalBypassTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,27 @@ public static void test7(String user, String password) {
129129
}
130130
}
131131

132+
public static void test8(String user, String password) {
133+
Cookie adminCookie = getCookies()[0];
134+
{
135+
// BAD: login may not happen
136+
if (adminCookie.getValue() == "false") // $ hasConditionalBypassTest
137+
authorize(user, password);
138+
else {
139+
// do something else
140+
doIt();
141+
}
142+
}
143+
{
144+
// obtainAuthor is not sensitive, so this is safe
145+
if (adminCookie.getValue() == "false")
146+
obtainAuthor();
147+
else {
148+
doIt();
149+
}
150+
}
151+
}
152+
132153
public static void login(String user, String password) {
133154
// login
134155
}
@@ -137,6 +158,14 @@ public static void reCheckAuth(String user, String password) {
137158
// login
138159
}
139160

161+
public static void authorize(String user, String password) {
162+
// login
163+
}
164+
165+
public static String obtainAuthor() {
166+
return "";
167+
}
168+
140169
public static Cookie[] getCookies() {
141170
// get cookies from a servlet
142171
return new Cookie[0];

0 commit comments

Comments
 (0)