Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TheDauntless
Copy link
Collaborator

If your PR is related to an issue. Please end your PR test with the following line:
This PR closes #2993

@cpholguera cpholguera changed the title Refactor of WebView URL Loading Port MASTG-TEST-0027 Nov 7, 2024
@cpholguera
Copy link
Collaborator

cpholguera commented Nov 7, 2024

@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]

@TheDauntless
Copy link
Collaborator Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `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.
Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Collaborator

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.

Comment on lines +19 to +21
1. WebViewClient.shouldOverrideUrlLoading
2. WebViewClient.shouldInterceptRequest
3. WebSettings.setSafeBrowsingEnabled
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Title: Testing for URL Loading in WebViews
Title: Testing for custom URL Loading in WebViews

@cpholguera cpholguera changed the title Port MASTG-TEST-0027 Port MASTG-TEST-0027: Testing for URL Loading in WebViews (android) Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MASTG v1->v2 MASTG-TEST-0027: Testing for URL Loading in WebViews (android)
3 participants