-
Notifications
You must be signed in to change notification settings - Fork 137
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
[Receipts] Enlarge receipt contents so that it's easily readable #13266
base: trunk
Are you sure you want to change the base?
Conversation
… before loading receipt URL for security purposes
…as selected site url
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
@AnirudhBhat Thanks for your work here! It works fine, but I am wondering if we could just inject HTML in the page and avoid all these changes related to the JS enabling? E.g.
And maybe to extract some code from shouldInterceptRequest to a helper to be able to have tests, but not sure if it worth it. wdyt? |
Closes: #12760
Note to reviewers: Please see if the changes are worth the fix
Description
This PR addresses the following improvements for the receipt preview feature:
Configured the WebView to scale content appropriately using viewport settings and JavaScript injection to ensure the receipt content fits the screen on all devices.
As a result of using Javascript, below security measures have been taken care of:
Strengthened WebView security by adding a domain name validation mechanism to ensure only trusted URLs are loaded.
Restricted unnecessary WebView features, such as file and content access, to reduce the attack surface.
Changes Made
Injected a viewport meta tag and zoom scaling via JavaScript in onPageFinished.
Enabled useWideViewPort and loadWithOverviewMode for responsive rendering.
Disabled unnecessary features like allowFileAccess and allowContentAccess.
Added validation in shouldOverrideUrlLoading to block untrusted domains and handle them appropriately.
Implemented a fallback for older APIs to ensure consistent behavior across devices.
Security Vulnerability Concern
The primary concern was the potential Cross-Site Scripting (XSS) and phishing attacks due to enabling JavaScript in the WebView. While JavaScript is essential for scaling and rendering rich content like receipts, it also opens up the possibility for:
If an untrusted URL or malicious script is loaded into the WebView, it could execute arbitrary JavaScript, potentially compromising sensitive user data or app security.
If the WebView loads a malicious URL that mimics a trusted domain, it could deceive users into sharing sensitive information.
By default, WebView settings like allowFileAccess and allowContentAccess could expose local files or content providers to unauthorized access if not properly secured.
Why Domain Validation Was Added
To mitigate these risks, domain validation was introduced as a safeguard to ensure the WebView only loads content from trusted sources. This addresses the vulnerabilities by:
Any URL that doesn't belong to the trusted domain(s) is rejected in the shouldOverrideUrlLoading method, ensuring only authorized content is rendered.
By restricting URL loading to a specific domain (e.g., https://your-trusted-domain.com), the app avoids loading scripts or assets from external or potentially harmful sources.
Steps to reproduce
The tests that have been performed
Above mentioned steps
Images/gif
Before and After Comparison
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: