CodeQL 文档

已启用 Android Webview 调试

ID: java/android/webview-debugging-enabled
Kind: path-problem
Security severity: 7.2
Severity: warning
Precision: high
Tags:
   - security
   - external/cwe/cwe-489
Query suites:
   - java-code-scanning.qls
   - java-security-extended.qls
   - java-security-and-quality.qls

点击查看 CodeQL 存储库中的查询

WebView.setWebContentsDebuggingEnabled 方法可以启用或禁用应用程序中任何 WebView 内容的调试功能。

您只应在开发过程中启用调试功能。创建生产版本时,应将其禁用。如果您启用调试功能,则可能会通过添加入口点或泄露敏感信息而使您的代码易受攻击。

建议

确保在生产版本中未启用调试功能,例如通过使用仅在调试版本中启用的标志来保护对 WebView.setWebContentsDebuggingEnabled(true) 的调用。

示例

在第一个(错误)示例中,始终启用 WebView 调试。而在“良好”情况下,仅当 android:debuggable 属性设置为 true 时才启用它。

// BAD - debugging is always enabled 
WebView.setWebContentsDebuggingEnabled(true);

// GOOD - debugging is only enabled when this is a debug build, as indicated by the debuggable flag being set.
if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) {
    WebView.setWebContentsDebuggingEnabled(true);
}

参考

  • ©GitHub 公司
  • 条款
  • 隐私