Skip to content

Commit 62c2191

Browse files
committed
Add QLDoc to guard and sanitizer
1 parent 58a0bcd commit 62c2191

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ private class DefaultIntentUriPermissionManipulationSink extends IntentUriPermis
3838
}
3939
}
4040

41+
/**
42+
* Sanitizer that prevents access to arbitrary content providers by modifying the Intent in one of
43+
* the following ways:
44+
* * Removing the flags `FLAG_GRANT_READ_URI_PERMISSION` and `FLAG_GRANT_WRITE_URI_PERMISSION`.
45+
* * Setting the flags to a combination that doesn't include `FLAG_GRANT_READ_URI_PERMISSION` or
46+
* `FLAG_GRANT_WRITE_URI_PERMISSION`.
47+
* * Replacing the data URI.
48+
*/
4149
private class IntentFlagsOrDataChangedSanitizer extends IntentUriPermissionManipulationSanitizer {
4250
IntentFlagsOrDataChangedSanitizer() {
4351
exists(MethodAccess ma, Method m |
@@ -60,6 +68,20 @@ private class IntentFlagsOrDataChangedSanitizer extends IntentUriPermissionManip
6068
}
6169
}
6270

71+
/**
72+
* A guard that checks an Intent's flags or data URI to make sure they are trusted.
73+
* It matches the following patterns:
74+
*
75+
* ```java
76+
* if (intent.getData().equals("trustedValue")) {}
77+
*
78+
* if (intent.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION == 0 &&
79+
* intent.getFlags() & Intent.FLAG_GRANT_WRITE_URI_PERMISSION == 0) {}
80+
*
81+
* if (intent.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION != 0 ||
82+
* intent.getFlags() & Intent.FLAG_GRANT_WRITE_URI_PERMISSION != 0) {}
83+
* ```
84+
*/
6385
private class IntentFlagsOrDataCheckedGuard extends IntentUriPermissionManipulationGuard {
6486
Expr condition;
6587

0 commit comments

Comments
 (0)