Skip to content

Commit cb77e46

Browse files
authored
Merge pull request github#4600 from porcupineyhairs/urirefactor
Java : Refactor all instances of `java.net.URI` into TypeUri
2 parents a908e59 + 0a028dc commit cb77e46

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

java/ql/src/experimental/Security/CWE/CWE-522/InsecureBasicAuth.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class URLConstructor extends ClassInstanceExpr {
6161
* Class of Java URI constructor.
6262
*/
6363
class URIConstructor extends ClassInstanceExpr {
64-
URIConstructor() { this.getConstructor().getDeclaringType().hasQualifiedName("java.net", "URI") }
64+
URIConstructor() { this.getConstructor().getDeclaringType() instanceof TypeUri }
6565

6666
predicate hasHttpStringArg() {
6767
(
@@ -185,7 +185,7 @@ predicate createURI(DataFlow::Node node1, DataFlow::Node node2) {
185185
exists(
186186
StaticMethodAccess ma // URI.create
187187
|
188-
ma.getMethod().getDeclaringType().hasQualifiedName("java.net", "URI") and
188+
ma.getMethod().getDeclaringType() instanceof TypeUri and
189189
ma.getMethod().hasName("create") and
190190
node1.asExpr() = ma.getArgument(0) and
191191
node2.asExpr() = ma

java/ql/src/semmle/code/java/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ private import semmle.code.java.Maps
99
private import semmle.code.java.dataflow.internal.ContainerFlow
1010
private import semmle.code.java.frameworks.spring.SpringController
1111
private import semmle.code.java.frameworks.spring.SpringHttp
12+
private import semmle.code.java.frameworks.Networking
1213
import semmle.code.java.dataflow.FlowSteps
1314

1415
/**
@@ -341,7 +342,7 @@ private predicate taintPreservingQualifierToMethod(Method m) {
341342
m.getDeclaringType() instanceof TypeFile and
342343
m.hasName("toURI")
343344
or
344-
m.getDeclaringType().hasQualifiedName("java.net", "URI") and
345+
m.getDeclaringType() instanceof TypeUri and
345346
m.hasName("toURL")
346347
or
347348
m instanceof GetterMethod and m.getDeclaringType() instanceof SpringUntrustedDataType
@@ -469,7 +470,7 @@ private predicate taintPreservingArgumentToMethod(Method method, int arg) {
469470
arg = 0
470471
or
471472
// A URI created from a tainted string is still tainted.
472-
method.getDeclaringType().hasQualifiedName("java.net", "URI") and
473+
method.getDeclaringType() instanceof TypeUri and
473474
method.hasName("create") and
474475
arg = 0
475476
or

java/ql/src/semmle/code/java/frameworks/Networking.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class TypeUrl extends RefType {
1919
TypeUrl() { hasQualifiedName("java.net", "URL") }
2020
}
2121

22+
/** The type `java.net.URI`. */
23+
class TypeUri extends RefType {
24+
TypeUri() { hasQualifiedName("java.net", "URI") }
25+
}
26+
2227
/** The method `java.net.URLConnection::getInputStream`. */
2328
class URLConnectionGetInputStreamMethod extends Method {
2429
URLConnectionGetInputStreamMethod() {

0 commit comments

Comments
 (0)