-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port MASTG-TEST-0027: Testing for URL Loading in WebViews (android) #3061
base: master
Are you sure you want to change the base?
Conversation
@TheDauntless please check the spell checker errors and remember to deprecate the old test and add also the covered_by field example: status: deprecated
covered_by: [MASTG-TEST-0203, MASTG-TEST-0x03] |
Good catch. Please review again :) |
|
||
## Overview | ||
|
||
By default, navigation events inside of a WebView will redirect to the default browser application. However, it is possible to stay within the WebView and handle all new page loads. This can be dangerous, as the new page may be malicious and interact with either the JavaScript bridge, or phish the user. The application should monitor navigation events inside the WebView to make sure that only legitimate pages are loaded, while others are redirected to the browser application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, navigation events inside of a WebView will redirect to the default browser application. However, it is possible to stay within the WebView and handle all new page loads. This can be dangerous, as the new page may be malicious and interact with either the JavaScript bridge, or phish the user. The application should monitor navigation events inside the WebView to make sure that only legitimate pages are loaded, while others are redirected to the browser application. | |
By default, navigation events inside of a WebView will redirect to the default browser application. However, it is possible to stay within the WebView and handle all new page loads. This can be dangerous, as the new page may be malicious and interact with either the JavaScript bridge (see @MASWE-0068), or phish the user. The application should monitor navigation events inside the WebView to make sure that only legitimate pages are loaded, while others are redirected to the browser application. |
## Steps | ||
|
||
1. Examine the application's code (see @MASTG-TECH-0023) | ||
2. Look for occurrences of WebViews being used and examine if they are configured with a custom `WebViewClient`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Look for occurrences of WebViews being used and examine if they are configured with a custom `WebViewClient`. | |
2. Look for occurrences of WebViews being used and examine if they are configured with a custom `WebViewClient`. This can be done e.g., by calling `webview.setWebViewClient(new MyWebViewClient());`. Alternatively, you can look for any class extending `WebViewClient`. |
|
||
1. Examine the application's code (see @MASTG-TECH-0023) | ||
2. Look for occurrences of WebViews being used and examine if they are configured with a custom `WebViewClient`. | ||
3. Search for and inspect the following interception callback functions for the `WebViewClient`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3. Search for and inspect the following interception callback functions for the `WebViewClient`: | |
3. Search for and inspect the following interception callback functions for the custom `WebViewClient`: |
2. Look for occurrences of WebViews being used and examine if they are configured with a custom `WebViewClient`. | ||
3. Search for and inspect the following interception callback functions for the `WebViewClient`: | ||
|
||
- `shouldOverrideUrlLoading` allows your application to either abort loading pages with suspicious content by returning `true` or allow the WebView to load the URL by returning `false`. Considerations: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `shouldOverrideUrlLoading` allows your application to either abort loading pages with suspicious content by returning `true` or allow the WebView to load the URL by returning `false`. Considerations: | |
- [`shouldOverrideUrlLoading`](https://developer.android.com/reference/android/webkit/WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView,%20android.webkit.WebResourceRequest)) allows your application to either abort loading pages with suspicious content by returning `true` or allow the WebView to load the URL by returning `false`. Considerations: |
- `shouldOverrideUrlLoading` allows your application to either abort loading pages with suspicious content by returning `true` or allow the WebView to load the URL by returning `false`. Considerations: | ||
- This method is not called for POST requests. | ||
- This method is not called for XmlHttpRequests, iFrames, "src" attributes included in HTML or `<script>` tags. Instead, `shouldInterceptRequest` should take care of this. | ||
- `shouldInterceptRequest` allows the application to return the data from resource requests. If the return value is null, the WebView will continue to load the resource as usual. Otherwise, the data returned by the `shouldInterceptRequest` method is used. Considerations: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `shouldInterceptRequest` allows the application to return the data from resource requests. If the return value is null, the WebView will continue to load the resource as usual. Otherwise, the data returned by the `shouldInterceptRequest` method is used. Considerations: | |
- [`shouldInterceptRequest`](https://developer.android.com/reference/android/webkit/WebViewClient#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest)) allows the application to return the data from resource requests. If the return value is null, the WebView will continue to load the resource as usual. Otherwise, the data returned by the `shouldInterceptRequest` method is used. Considerations: |
- The `WebViewClient` is missing the `shouldOverrideUrlLoading` or `shouldInterceptRequest` handlers | ||
- The `shouldOverrideUrlLoading` or `shouldInterceptRequest` handlers do not correctly prevent untrusted data from being loaded in the `WebView` | ||
|
||
If the `WebView` does not have a custom `WebViewClient`, then any navigation event will automatically trigger the default browser. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure the last sentence is needed, since the test case is only for webviews with custom clients?
|
||
## Overview | ||
|
||
By default, navigation events inside of a WebView will redirect to the default browser application. However, it is possible to stay within the WebView and handle all new page loads. This can be dangerous, as the new page may be malicious and interact with either the JavaScript bridge, or phish the user. The application should monitor navigation events inside the WebView to make sure that only legitimate pages are loaded, while others are redirected to the browser application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, navigation events inside of a WebView will redirect to the default browser application. However, it is possible to stay within the WebView and handle all new page loads. This can be dangerous, as the new page may be malicious and interact with either the JavaScript bridge, or phish the user. The application should monitor navigation events inside the WebView to make sure that only legitimate pages are loaded, while others are redirected to the browser application. | |
By default, navigation events inside of a WebView will redirect to the default browser application. However, it is possible to stay within the WebView and handle all new page loads. This can be dangerous, as the new page may be malicious and interact with either the JavaScript bridge (see @MASWE-0068), or phish the user. The application should monitor navigation events inside the WebView to make sure that only legitimate pages are loaded, while others are redirected to the browser application. |
1. WebViewClient.shouldOverrideUrlLoading | ||
2. WebViewClient.shouldInterceptRequest | ||
3. WebSettings.setSafeBrowsingEnabled | ||
3. Use any WebView inside the app and trigger navigation events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3. Use any WebView inside the app and trigger navigation events | |
3. Use every WebView inside the app and trigger navigation events, using a variety of trusted and non-trusted URLs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it is obvious what a non-trusted URL is in this context? But I think a tester needs to try various URLs, otherwise, potentially only the happy path for the Custom Webview will be triggered.
1. WebViewClient.shouldOverrideUrlLoading | ||
2. WebViewClient.shouldInterceptRequest | ||
3. WebSettings.setSafeBrowsingEnabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. WebViewClient.shouldOverrideUrlLoading | |
2. WebViewClient.shouldInterceptRequest | |
3. WebSettings.setSafeBrowsingEnabled | |
1. `WebViewClient.shouldOverrideUrlLoading` | |
2. `WebViewClient.shouldInterceptRequest` | |
3. `WebSettings.setSafeBrowsingEnabled` |
@@ -0,0 +1,44 @@ | |||
--- | |||
Title: Testing for URL Loading in WebViews |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Title: Testing for URL Loading in WebViews | |
Title: Testing for custom URL Loading in WebViews |
If your PR is related to an issue. Please end your PR test with the following line:
This PR closes #2993