교차 앱 스크립팅
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
OWASP 카테고리: MASVS-CODE: 코드 품질
개요
WebView는 Android 애플리케이션에 내장된 브라우저 구성요소로,
앱 내에 웹 콘텐츠를 표시하도록 용이하게 합니다. HTML, CSS 및
JavaScript를 사용하여 상속할 수 있습니다.
교차 앱 스크립팅은 악성 코드의 실행과 광범위하게 관련되어 있습니다.
희생자 애플리케이션의 맥락에서 일어납니다 이 문서의 목적상 이 주제는 악성 JavaScript 코드를 취약한 WebView에 삽입하는 것으로 제한됩니다.
앱이 충분한 유효성 검사나 정리 없이 악성 JavaScript를 WebView에 허용하면 애플리케이션이 교차 앱 스크립팅에 취약해집니다.
영향
교차 앱 스크립팅 취약점은 공격자가 제어하는 JavaScript 콘텐츠가 검증 또는 정리되지 않고 취약한 앱의 WebView에 전달될 때 악용될 수 있습니다. 따라서
피해 애플리케이션의 WebView의 컨텍스트에서 실행됩니다. 그러면 악성 JavaScript 코드는 피해자 앱과 동일한 권한을 사용할 수 있으므로 민감한 사용자 데이터 도용 및 계정 도용이 발생할 수 있습니다.
완화 조치
자바스크립트 사용 중지
애플리케이션에 JavaScript가 필요하지 않은 경우 JavaScript를 사용 중지하면 위협이 되지 않습니다.
Kotlin
// Get the WebView Object
val webView = findViewById<WebView>(R.id.webView)
val webSettings = webView.settings
// Disable JavaScript
webSettings.javaScriptEnabled = false
자바
// Get the WebView Object
WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
// Disable JavaScript for the WebView
webSettings.setJavaScriptEnabled(false);
애플리케이션에 JavaScript가 필요한 경우
JavaScript가 WebView에 전달됩니다. WebView에서 임의의 실행을 허용하지 않음
다음 섹션의 안내를 참고하세요.
예상 콘텐츠만 WebView에 로드되는지 확인
shouldOverrideUrlLoading()
, loadUrl()
또는 evaluateJavascript()
,
와 같은 메서드를 사용할 때는 전달된 URL이 확인되었는지 확인합니다. 앞서 언급했듯이 WebView에 전달되는 모든 JavaScript는
예상한 도메인에서 비롯되므로 로드 중인 것을 확인하는 것이 중요합니다.
OWASP의 입력 유효성 검사 문서 및 이 Android
WebView의 보안 체크리스트를 참조하세요.
WebView의 보안 파일 액세스 설정 지정
파일에 액세스할 수 없게 하면 임의의 JavaScript에서
WebView 내에서 실행됩니다.다음 WebSettings
는
다음 사항을 고려해야 합니다.
- 파일 액세스를 사용 중지합니다. 기본적으로
setAllowFileAccess
은 API 수준 29 이하에서 True
로 설정되어 로컬 파일에 대한 액세스를 허용합니다. API 수준 30 이상에서는 기본값이 False
입니다. 파일 액세스가 허용되지 않도록 하려면
명시적으로 setAllowFileAccess
을 False
로 설정
콘텐츠 액세스를 사용 중지합니다. setAllowContentAccess
의 기본 설정은 True
입니다. 콘텐츠 URL 액세스를 사용하면 WebView가 시스템에 설치된 콘텐츠 제공업체에서 콘텐츠를 로드할 수 있습니다. 앱에 콘텐츠 액세스가 필요하지 않은 경우
장애 발생 시 잠재적인 오용을 방지하기 위해 setAllowContentAccess
를 False
로
교차 앱 스크립팅 공격
kotlin
kotlin
webView.settings.javaScriptEnabled = false
webView.settings.domStorageEnabled = true
webView.settings.allowFileAccess = false
webView.settings.allowContentAccess = false
자바
java
webView.getSettings().setJavaScriptEnabled(false);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAllowFileAccess(false);
webView.getSettings().setAllowContentAccess(false);
세이프 브라우징 사용
AndroidManifest.xml
에서 세이프 브라우징을 사용 설정하여 다음 주소로 전달된 URL을 스캔하세요.
피싱 또는 악성 도메인용 WebView:
<meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
android:value="true" />
리소스
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[],[],null,["# Cross-app scripting\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-CODE: Code Quality](https://mas.owasp.org/MASVS/10-MASVS-CODE)\n\nOverview\n--------\n\nA WebView is an embedded browser component in Android applications that\nfacilitates the display of web content within an app. It renders HTML, CSS, and\nJavaScript within the app's user interface.\n\nCross-App Scripting is broadly associated with the execution of malicious code\nin the context of a victim application. For the purposes of this documentation,\nthe subject will be constrained specifically to the injection of malicious\nJavaScript code into a vulnerable WebView.\n\nWhen an app accepts malicious JavaScript into a WebView without sufficient\nvalidation or sanitization, the application is vulnerable to cross-app\nScripting.\n\nImpact\n------\n\nCross-app scripting vulnerabilities can be exploited when attacker-controlled\nJavaScript content is passed to the vulnerable app's WebView without being\nvalidated or sanitized. As a result, the JavaScript code provided by the\nattacker is executed in the context of the victim application's WebView. The\nmalicious JavaScript code can then use the same permissions as the victim app's,\nwhich may lead to theft of sensitive user data, and account hijacking.\n\nMitigations\n-----------\n\n### Disable JavaScript\n\nIf your application does not require JavaScript, disabling it will ensure it\ndoes not become a threat: \n\n### Kotlin\n\n // Get the WebView Object\n val webView = findViewById\u003cWebView\u003e(R.id.webView)\n val webSettings = webView.settings\n\n // Disable JavaScript\n webSettings.javaScriptEnabled = false\n\n### Java\n\n // Get the WebView Object\n WebView webView = (WebView) findViewById(R.id.webView);\n WebSettings webSettings = webView.getSettings();\n\n // Disable JavaScript for the WebView\n webSettings.setJavaScriptEnabled(false);\n\nIf your application does require JavaScript, ensure that you own or control any\nJavaScript passed to WebView. Avoid allowing WebView to execute arbitrary\nJavaScript, see the guidance in the next section.\n\n### Ensure only expected content is loaded into WebView\n\nWhen using methods like [`shouldOverrideUrlLoading()`](/reference/android/webkit/WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView,%20android.webkit.WebResourceRequest)), [`loadUrl()`](/reference/android/webkit/WebView#loadUrl(java.lang.String)), or\n[`evaluateJavascript()`](/reference/android/webkit/WebView#evaluateJavascript(java.lang.String,%20android.webkit.ValueCallback%3Cjava.lang.String%3E))`,` make sure that any URLs passed to them are\nchecked. As stated earlier, any JavaScript passed to the WebView should only\ncome from expected domains, so it is important to verify what is being loaded.\n\nCheck OWASP's input validation [documentation](https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html) and this Android\nsecurity [checklist](https://blog.oversecured.com/Android-security-checklist-webview/) for WebViews for good advice and examples.\n\n### Set secure file access settings for WebView\n\nEnsuring that files are not accessible can prevent arbitrary JavaScript from\nbeing executed within WebViews.The following [`WebSettings`](/reference/android/webkit/WebSettings) should be\nconsidered when securing file access:\n\n- Disable file access. By default, [`setAllowFileAccess`](/reference/android/webkit/WebSettings#setAllowFileAccess(boolean)) is set to `True` in API level 29 and lower which will permit access to local files. In API level 30 and higher the default is `False`. To ensure file access is not permitted, explicitly set `setAllowFileAccess` to `False`\n- Disable content access. The default setting of [`setAllowContentAccess`](/reference/android/webkit/WebSettings#setAllowContentAccess(boolean)) is\n `True`. Content URL access allows WebView to load content from a content\n provider installed in the system. If your app does not require content access,\n set `setAllowContentAccess` to `False` to prevent potential misuse in case of a\n cross-app scripting attack.\n\n- kotlin\n `kotlin\n webView.settings.javaScriptEnabled = false\n webView.settings.domStorageEnabled = true\n webView.settings.allowFileAccess = false\n webView.settings.allowContentAccess = false`\n\n- java\n `java\n webView.getSettings().setJavaScriptEnabled(false);\n webView.getSettings().setDomStorageEnabled(true);\n webView.getSettings().setAllowFileAccess(false);\n webView.getSettings().setAllowContentAccess(false);`\n\n### Enable Safe Browsing\n\nEnable Safe Browsing in [`AndroidManifest.xml`](/guide/topics/manifest/manifest-intro) to scan URLs passed to\nWebView for phishing or malicious domains.: \n\n \u003cmeta-data android:name=\"android.webkit.WebView.EnableSafeBrowsing\"\n android:value=\"true\" /\u003e\n\nResources\n---------\n\n- [Safe Browsing documentation](/privacy-and-security/safetynet/safebrowsing)\n- [WebView developer reference](/reference/android/webkit/WebView)\n- [WebSettings for WebView developer reference](/reference/android/webkit/WebSettings)\n- [setAllowFileAccess developer documentation](/reference/android/webkit/WebSettings#setAllowFileAccess(boolean))\n- [setAllowContentAccess developer reference](/reference/android/webkit/WebSettings#setAllowContentAccess(boolean))"]]