mirror of
https://github.com/github/codeql.git
synced 2026-05-05 13:45:19 +02:00
Add Fragment injection query
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0"
|
||||
package="com.example.myapp">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,11 @@
|
||||
import java
|
||||
import semmle.code.java.security.FragmentInjectionQuery
|
||||
import TestUtilities.InlineFlowTest
|
||||
|
||||
class Test extends InlineFlowTest {
|
||||
override DataFlow::Configuration getValueFlowConfig() { none() }
|
||||
|
||||
override TaintTracking::Configuration getTaintFlowConfig() {
|
||||
result instanceof FragmentInjectionTaintConf
|
||||
}
|
||||
}
|
||||
39
java/ql/test/query-tests/security/CWE-470/MainActivity.java
Normal file
39
java/ql/test/query-tests/security/CWE-470/MainActivity.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.example.myapp;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
public class MainActivity extends FragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstance) {
|
||||
try {
|
||||
super.onCreate(savedInstance);
|
||||
final String fname = getIntent().getStringExtra("fname");
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
Class<Fragment> fClass = (Class<Fragment>) Class.forName(fname);
|
||||
ft.add(fClass.newInstance(), ""); // $ hasTaintFlow
|
||||
ft.add(0, Fragment.instantiate(this, fname), null); // $ hasTaintFlow
|
||||
ft.add(0, Fragment.instantiate(this, fname, null)); // $ hasTaintFlow
|
||||
ft.add(0, fClass, null, ""); // $ hasTaintFlow
|
||||
ft.add(0, fClass.newInstance(), ""); // $ hasTaintFlow
|
||||
ft.attach(fClass.newInstance()); // $ hasTaintFlow
|
||||
ft.replace(0, fClass, null); // $ hasTaintFlow
|
||||
ft.replace(0, fClass.newInstance()); // $ hasTaintFlow
|
||||
ft.replace(0, fClass, null, ""); // $ hasTaintFlow
|
||||
ft.replace(0, fClass.newInstance(), ""); // $ hasTaintFlow
|
||||
|
||||
ft.add(Fragment.class.newInstance(), ""); // Safe
|
||||
ft.attach(Fragment.class.newInstance()); // Safe
|
||||
ft.replace(0, Fragment.class.newInstance(), ""); // Safe
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
1
java/ql/test/query-tests/security/CWE-470/options
Normal file
1
java/ql/test/query-tests/security/CWE-470/options
Normal file
@@ -0,0 +1 @@
|
||||
//semmle-extractor-options: --javac-args -cp ${testdir}/../../../stubs/google-android-9.0.0
|
||||
Reference in New Issue
Block a user