Skip to content

Commit 19d2a40

Browse files
authored
Add AndroidRString RefType to clarify the Android query
1 parent 08ab7b0 commit 19d2a40

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99

1010
import java
1111

12+
/**
13+
* The Java class `android.R.string` specific to Android applications, which contains references to application specific resources defined in /res/values/strings.xml.
14+
* For example, <resources>...<string name="host">example.com</string>...</resources> in the application com.example.android.web can be referred as R.string.host with the type com.example.android.web.R$string
15+
*/
16+
class AndroidRString extends RefType {
17+
AndroidRString() { this.hasQualifiedName(_, "R$string") }
18+
}
19+
1220
/**
1321
* The Java class `android.net.Uri` and `java.net.URL`.
1422
*/
@@ -63,12 +71,13 @@ class HostVerificationMethodAccess extends MethodAccess {
6371
.getRepresentedString()
6472
.charAt(0) != "." //"."+var2, check string constant "." e.g. String domainName = "example.com"; Uri.parse(url).getHost().endsWith("www."+domainName)
6573
or
66-
exists(MethodAccess ma, Method m |
74+
exists(MethodAccess ma, Method m, Field f |
6775
this.getArgument(0) = ma and
6876
ma.getMethod() = m and
6977
m.hasName("getString") and
7078
m.getDeclaringType().getQualifiedName() = "android.content.res.Resources" and
71-
ma.getArgument(0).toString().indexOf("R.string") = 0
79+
ma.getArgument(0).(FieldRead).getField() = f and
80+
f.getDeclaringType() instanceof AndroidRString
7281
) //Check resource properties in /res/values/strings.xml in Android mobile applications using res.getString(R.string.key)
7382
or
7483
this

0 commit comments

Comments
 (0)