-
Notifications
You must be signed in to change notification settings - Fork 48
Surface gateway HTTP errors and allow compatible mixed content so Stripe pages load #48
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,14 @@ | ||||||||||||
| package eu.livotov.labs.android.d3s; | ||||||||||||
|
|
||||||||||||
| import android.content.Context; | ||||||||||||
| import android.os.Build; | ||||||||||||
| import android.text.TextUtils; | ||||||||||||
| import android.util.AttributeSet; | ||||||||||||
| import android.util.Log; | ||||||||||||
| import android.webkit.WebChromeClient; | ||||||||||||
| import android.webkit.WebResourceRequest; | ||||||||||||
| import android.webkit.WebResourceResponse; | ||||||||||||
| import android.webkit.WebSettings; | ||||||||||||
| import android.webkit.WebView; | ||||||||||||
| import android.webkit.WebViewClient; | ||||||||||||
|
|
||||||||||||
|
|
@@ -75,6 +79,9 @@ public D3SView(final Context context) { | |||||||||||
| private void initUI() { | ||||||||||||
| getSettings().setJavaScriptEnabled(true); | ||||||||||||
| getSettings().setBuiltInZoomControls(true); | ||||||||||||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||||||||||||
| getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); | ||||||||||||
| } | ||||||||||||
| addJavascriptInterface(new D3SJSInterface(), JavaScriptNS); | ||||||||||||
|
|
||||||||||||
| setWebViewClient(new WebViewClient() { | ||||||||||||
|
|
@@ -117,6 +124,20 @@ public void onReceivedError(WebView view, int errorCode, String description, Str | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| @Override | ||||||||||||
| public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { | ||||||||||||
| // Forward HTTP errors from the gateway (for example Stripe) so callers | ||||||||||||
| // can react to a non 2xx response instead of seeing a blank screen. | ||||||||||||
|
Comment on lines
+127
to
+130
|
||||||||||||
| String failingUrl = request.getUrl().toString(); | ||||||||||||
| if (isPostbackUrl(failingUrl)) return; | ||||||||||||
| int status = errorResponse.getStatusCode(); | ||||||||||||
| String reason = errorResponse.getReasonPhrase(); | ||||||||||||
| Log.w("D3SView", "HTTP " + status + " " + reason + " for " + failingUrl); | ||||||||||||
|
||||||||||||
| Log.w("D3SView", "HTTP " + status + " " + reason + " for " + failingUrl); | |
| Log.w("D3SView", "HTTP " + status + " " + reason); |
Copilot
AI
Apr 22, 2026
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.
onReceivedHttpError is invoked for any resource (subframes, images, scripts) that returns an HTTP error. Forwarding every such failure to onAuthorizationWebPageLoadingError can produce false negatives (e.g., a 404 analytics pixel) and abort an otherwise successful 3DS flow. Please gate the callback to the main frame only (e.g., request.isForMainFrame()), and consider only forwarding when the failing URL matches the current top-level page being loaded.
Copilot
AI
Apr 22, 2026
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.
isPostbackUrl uses toLowerCase() without an explicit locale, which can behave incorrectly on some locales (e.g., Turkish) and potentially break postback detection. Use a locale-stable comparison (e.g., toLowerCase(Locale.ROOT) or regionMatches(true, ...)) to keep URL matching consistent.
| return url.toLowerCase().startsWith(postbackUrl.toLowerCase()); | |
| return url != null | |
| && postbackUrl != null | |
| && url.length() >= postbackUrl.length() | |
| && url.regionMatches(true, 0, postbackUrl, 0, postbackUrl.length()); |
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.
Enabling
MIXED_CONTENT_COMPATIBILITY_MODEglobally weakens WebView security (HTTPS pages can load HTTP subresources), increasing the risk of content injection during payment flows. Consider making this behavior opt-in (setter/attribute), or scoping it to only the specific authorization session where it’s needed, with a clear default that preserves the prior stricter behavior.