-
Notifications
You must be signed in to change notification settings - Fork 136
[Receipts] Enlarge receipt contents so that it's easily readable #13266
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
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.
|
...rc/main/kotlin/com/woocommerce/android/ui/payments/receipt/preview/ReceiptPreviewFragment.kt
Fixed
Show fixed
Hide fixed
|
@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? |
|
@kidinov Thanks for the good suggestion! I've implemented the solution that modifies html content instead of injecting javascript. Please take a look. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #13266 +/- ##
=========================================
Coverage 41.07% 41.08%
- Complexity 6417 6422 +5
=========================================
Files 1321 1322 +1
Lines 77221 77238 +17
Branches 10657 10659 +2
=========================================
+ Hits 31722 31733 +11
- Misses 42687 42690 +3
- Partials 2812 2815 +3 ☔ View full report in Codecov by Sentry. |
| "UTF-8", | ||
| modifiedHtml.byteInputStream() | ||
| ) | ||
| } catch (e: MalformedURLException) { |
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.
I'd propose to crash in both cases, as in both cases, it means the feature doesn't function, and the only difference is that in the case of crash, we will catch it early, while in the second later or even never
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.
Makes sense. Done: 38f7f65
kidinov
left a comment
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.
LGTM! I left, imo important comment regarding error handling, please take a look

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.txtif 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: