我想编写一个强化规则,在 android 代码库中查找“addJavascriptInterface”的实例。
<?xml version="1.0" encoding="UTF-8"?>
<RulePack xmlns="xmlns://www.fortifysoftware.com/schema/rules">
<RulePackID>80B927D2-5408-41B4-B47C-B4958DAAECBD</RulePackID>
<SKU>SKU-80B927D2-5408-41B4-B47C-B4958DAAECBD</SKU>
<Name><![CDATA[android.xml]]></Name>
<Version>1.0</Version>
<Description><![CDATA[Description for android.xml]]></Description>
<Rules version="3.13">
<RuleDefinitions>
<SemanticRule formatVersion="3.13" language="java">
<MetaInfo>
<Group name="Accuracy">5.0</Group>
<Group name="Impact">5.0</Group>
<Group name="RemediationEffort">15.0</Group>
<Group name="Probability">5.0</Group>
</MetaInfo>
<RuleID>CC4B8F82-0824-4DF1-8A5F-513DC6820B99</RuleID>
<VulnCategory>Testjsinterface</VulnCategory>
<DefaultSeverity>5.0</DefaultSeverity>
<Description/>
<Type>default</Type>
<FunctionIdentifier>
<NamespaceName>
<Pattern>\w*</Pattern>
</NamespaceName>
<ClassName>
<Pattern>WebView</Pattern>
</ClassName>
<FunctionName>
<Pattern>addJavascriptInterface</Pattern>
</FunctionName>
<ApplyTo implements="true" overrides="true" extends="true"/>
</FunctionIdentifier>
</SemanticRule>
</RuleDefinitions>
</Rules>
</RulePack>
当我尝试针对代码库运行 fortify 时,我得到以下信息:-
[warning]: The following references to java classes could not be resolved. Please make sure to supply all the required jar files that contain these classes to SCA.
Override
android.app.Activity
android.content.res.AssetManager
android.os.Bundle
android.util.Log
android.view.KeyEvent
android.webkit.WebSettings
android.webkit.WebView
android.webkit.WebViewClient
所以我尝试按如下方式运行强化:-
bin/sourceanalyzer ~/repos/android-rule-tests/WebViewTest -cp ~/android-sdks/platforms/android-16/android.jar
警告消失了,但规则似乎仍然没有触发——可能出了什么问题?
编辑为清楚起见,WebViewTest 是一个使用 addJavascriptInterface 的示例项目。
EDIT2 为清楚起见添加了一些代码
package org.infil00p.phoneTest;
import java.io.IOException;
import com.infil00p.phoneTest.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.content.res.AssetManager;
public class TestActivity extends Activity {
WebView appView;
TestWebViewClient testClient;
String TAG="FAILTAG";
Bolt data = new Bolt();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
testClient = new TestWebViewClient();
appView = (WebView) findViewById(R.id.appView);
appView.getSettings().setDatabaseEnabled(true);
appView.getSettings().setJavaScriptEnabled(true);
appView.addJavascriptInterface(data, "test");
appView.setWebViewClient(testClient);
appView.loadUrl("file:///android_asset/index.html");
}
....
EDIT3 我对此进行了一些尝试,最终得出结论,在我的特定情况下,语义规则不会触发,直到它看到在同一文件中的类中定义的函数。获取 android 源并复制 WebView.java 的源会导致规则触发(这是一件可怕的事情,但我只是在玩耍)。