Skip to content

Commit d75841d

Browse files
authored
Add sample usage and remove unused imports
1 parent 3b1dad8 commit d75841d

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

java/ql/src/experimental/CWE-939/IncorrectURLVerification.ql

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
*/
99

1010
import java
11-
import semmle.code.java.dataflow.FlowSources
12-
import semmle.code.java.dataflow.TaintTracking
13-
import DataFlow
14-
import PathGraph
1511

1612

1713
/**
@@ -49,16 +45,16 @@ class HostVerificationMethodAccess extends MethodAccess {
4945
) and
5046
this.getMethod().getNumberOfParameters() = 1 and
5147
(
52-
this.getArgument(0).(StringLiteral).getRepresentedString().charAt(0) != "." or //string constant comparison
53-
this.getArgument(0).(AddExpr).getLeftOperand().(VarAccess).getVariable().getAnAssignedValue().(StringLiteral).getRepresentedString().charAt(0) != "." or //var1+var2, check var1 starts with "."
54-
this.getArgument(0).(AddExpr).getLeftOperand().(StringLiteral).getRepresentedString().charAt(0) != "." or //"."+var2, check string constant "."
55-
exists (MethodAccess ma | this.getArgument(0) = ma and ma.getMethod().hasName("getString") and ma.getArgument(0).toString().indexOf("R.string") = 0) or //res.getString(R.string.key)
56-
this.getArgument(0).(VarAccess).getVariable().getAnAssignedValue().(StringLiteral).getRepresentedString().charAt(0) != "." //check variable starts with "."
48+
this.getArgument(0).(StringLiteral).getRepresentedString().charAt(0) != "." or //string constant comparison e.g. uri.getHost().endsWith("example.com")
49+
this.getArgument(0).(AddExpr).getLeftOperand().(VarAccess).getVariable().getAnAssignedValue().(StringLiteral).getRepresentedString().charAt(0) != "." or //var1+var2, check var1 starts with "." e.g. String domainName = "example"; Uri.parse(url).getHost().endsWith(domainName+".com")
50+
this.getArgument(0).(AddExpr).getLeftOperand().(StringLiteral).getRepresentedString().charAt(0) != "." or //"."+var2, check string constant "." e.g. String domainName = "example.com"; Uri.parse(url).getHost().endsWith("www."+domainName)
51+
exists (MethodAccess ma | this.getArgument(0) = ma and ma.getMethod().hasName("getString") and ma.getArgument(0).toString().indexOf("R.string") = 0) or //Check resource properties in /res/values/strings.xml in Android mobile applications using res.getString(R.string.key)
52+
this.getArgument(0).(VarAccess).getVariable().getAnAssignedValue().(StringLiteral).getRepresentedString().charAt(0) != "." //check variable starts with "." e.g. String domainName = "example.com"; Uri.parse(url).getHost().endsWith(domainName)
5753
)
5854
}
5955
}
6056

6157
from UriGetHostMethod um, MethodAccess uma, HostVerificationMethodAccess hma
6258
where hma.getQualifier() = uma and uma.getMethod() = um
6359
select "Potentially improper URL verification with $@ in $@ having $@.",
64-
hma, hma.getFile(), hma.getArgument(0), "user-provided value"
60+
hma, hma.getFile(), hma.getArgument(0), "user-provided value"

0 commit comments

Comments
 (0)