Skip to content

Commit b0afba4

Browse files
authored
Merge pull request github#16761 from owen-mc/java/reverse-dns-get-loopback-address
Java: Exclude loopback address from reverse DNS source
2 parents c0df229 + 9aa0c9f commit b0afba4

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Excluded reverse DNS from the loopback address as a source of untrusted data.

java/ql/lib/semmle/code/java/dataflow/FlowSources.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private class ReverseDnsSource extends RemoteFlowSource {
126126
m.getMethod() instanceof ReverseDnsMethod and
127127
not exists(MethodCall l |
128128
(variableStep(l, m.getQualifier()) or l = m.getQualifier()) and
129-
l.getMethod().getName() = "getLocalHost"
129+
(l.getMethod().getName() = "getLocalHost" or l.getMethod().getName() = "getLoopbackAddress")
130130
)
131131
)
132132
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void main(HttpServletRequest request) throws Exception {
3838
}
3939

4040
// FALSE NEGATIVE: we have no way of telling that the skipped method is sensitive
41-
if (adminCookie.getValue() == "false") // $ MISSING: $ hasConditionalBypassTest
41+
if (adminCookie.getValue() == "false") // $ MISSING: hasConditionalBypassTest
4242
doReallyImportantSecurityWork();
4343

4444
InetAddress local = InetAddress.getLocalHost();
@@ -49,6 +49,15 @@ public static void main(HttpServletRequest request) throws Exception {
4949
if (Inet4Address.getLocalHost().getCanonicalHostName().equals("localhost")) {
5050
login(user, password);
5151
}
52+
53+
InetAddress loopback = InetAddress.getLoopbackAddress();
54+
// GOOD: reverse DNS on loopback address is fine
55+
if (loopback.getCanonicalHostName().equals("localhost")) {
56+
login(user, password);
57+
}
58+
if (Inet4Address.getLoopbackAddress().getCanonicalHostName().equals("localhost")) {
59+
login(user, password);
60+
}
5261
}
5362

5463
public static void test(String user, String password) {

0 commit comments

Comments
 (0)