mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
Add Fragment injection in PreferenceActivity query
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
class UnsafeActivity extends PreferenceActivity {
|
||||
|
||||
@Override
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
// BAD: any Fragment name can be provided.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SafeActivity extends PreferenceActivity {
|
||||
@Override
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
// Good: only trusted Fragment names are allowed.
|
||||
return SafeFragment1.class.getName().equals(fragmentName)
|
||||
|| SafeFragment2.class.getName().equals(fragmentName)
|
||||
|| SafeFragment3.class.getName().equals(fragmentName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
|
||||
<qhelp>
|
||||
<include src="FragmentInjection.inc.qhelp"></include>
|
||||
</qhelp>
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @name Android Fragment injection in PreferenceActivity
|
||||
* @description An insecure implementation of the isValidFragment method
|
||||
* of the PreferenceActivity class may lead to Fragment injection.
|
||||
* @kind problem
|
||||
* @problem.severity error
|
||||
* @security-severity 9.8
|
||||
* @precision high
|
||||
* @id java/android/fragment-injection-preference-activity
|
||||
* @tags security
|
||||
* external/cwe/cwe-470
|
||||
*/
|
||||
|
||||
import java
|
||||
import semmle.code.java.security.FragmentInjection
|
||||
|
||||
from IsValidFragmentMethod m
|
||||
where m.isUnsafe()
|
||||
select m,
|
||||
"The 'isValidFragment' method always returns true. This makes the exported Activity $@ vulnerable to Fragment Injection.",
|
||||
m.getDeclaringType(), m.getDeclaringType().getName()
|
||||
Reference in New Issue
Block a user