Optionally allow insecure HTTP requests through internet helper

This commit is contained in:
Arjan Schrijver
2025-12-25 14:45:08 +01:00
committed by Arjan Schrijver
parent 4f3c521f91
commit b950e91c4d
4 changed files with 22 additions and 14 deletions
@@ -86,10 +86,10 @@ object InternetHelperSingleton {
}
@Throws(RemoteException::class, InterruptedException::class)
fun send(webRequest: Uri): WebResourceResponse? {
fun send(webRequest: Uri, allowInsecure: Boolean): WebResourceResponse? {
val latch = CountDownLatch(1)
var result: WebResourceResponse? = null
val request = HttpGetRequest(webRequest.toString(), HttpHeaders())
val request = HttpGetRequest(webRequest.toString(), allowInsecure, HttpHeaders())
LOG.debug("Forwarding GET request to {} to internet helper app", webRequest)
try {
@@ -52,12 +52,12 @@ class InternetUtils {
requestHeaders: Map<String, String> = emptyMap(),
body: String? = null,
bodyContentType: String = "text/plain",
insecure: Boolean = false
allowInsecure: Boolean = false
): String? {
val response: WebResourceResponse? = if (GBApplication.hasDirectInternetAccess()) {
directRequest(uri, method, requestHeaders, body, bodyContentType, insecure)
directRequest(uri, method, requestHeaders, body, bodyContentType, allowInsecure)
} else {
InternetHelperSingleton.send(uri)
InternetHelperSingleton.send(uri, allowInsecure)
}
if (response == null) return null
@@ -71,7 +71,7 @@ class InternetUtils {
requestHeaders: Map<String, String> = emptyMap(),
body: String? = null,
bodyContentType: String = "text/plain",
insecure: Boolean = false
allowInsecure: Boolean = false
): JSONObject? {
val text = doStringRequest(
uri,
@@ -79,7 +79,7 @@ class InternetUtils {
requestHeaders,
body,
bodyContentType,
insecure
allowInsecure
)
try {
return JSONObject(text)
@@ -101,10 +101,10 @@ class InternetUtils {
requestHeaders = emptyMap(),
body = null,
bodyContentType = "application/octet-stream",
insecure = false
allowInsecure = false
)
} else {
InternetHelperSingleton.send(uri)
InternetHelperSingleton.send(uri, false)
}
response?.data?.use { input ->
@@ -129,10 +129,10 @@ class InternetUtils {
requestHeaders: Map<String, String>,
body: String?,
bodyContentType: String,
insecure: Boolean
allowInsecure: Boolean
): WebResourceResponse {
val client = if (insecure) createInsecureClient() else defaultClient
val client = if (allowInsecure) createInsecureClient() else defaultClient
val builder = Request.Builder().url(uri.toString())
@@ -134,7 +134,7 @@ public class GBWebClient extends WebViewClient {
if (!forceLocal && !directInternetAccess && InternetHelperSingleton.INSTANCE.ensureInternetHelperBound()) {
LOG.debug("WEBVIEW forwarding request to the internet helper");
try {
WebResourceResponse wrr = InternetHelperSingleton.INSTANCE.send(requestedUri);
WebResourceResponse wrr = InternetHelperSingleton.INSTANCE.send(requestedUri, false);
if (wrr != null && wrr.getStatusCode() < 400)
return wrr;
else
@@ -7,19 +7,22 @@ import androidx.annotation.NonNull;
public class HttpGetRequest implements Parcelable {
private final String url;
private final boolean allowInsecure;
private final HttpHeaders headers;
protected HttpGetRequest(final Parcel in) {
url = in.readString();
allowInsecure = in.readByte() != 0; // readBoolean() requires API level 29
headers = in.readParcelable(HttpGetRequest.class.getClassLoader());
}
public HttpGetRequest(String url, HttpHeaders headers) {
public HttpGetRequest(String url, boolean allowInsecure, HttpHeaders headers) {
this.url = url;
this.allowInsecure = allowInsecure;
this.headers = headers;
}
public static final Creator<HttpGetRequest> CREATOR = new Creator<HttpGetRequest>() {
public static final Creator<HttpGetRequest> CREATOR = new Creator<>() {
@Override
public HttpGetRequest createFromParcel(final Parcel in) {
return new HttpGetRequest(in);
@@ -39,6 +42,7 @@ public class HttpGetRequest implements Parcelable {
@Override
public void writeToParcel(@NonNull final Parcel dest, final int flags) {
dest.writeString(url);
dest.writeByte((byte) (allowInsecure ? 1 : 0)); // writeBoolean() requires API level 29
dest.writeParcelable(headers, 0);
}
@@ -46,6 +50,10 @@ public class HttpGetRequest implements Parcelable {
return url;
}
public boolean getAllowInsecure() {
return allowInsecure;
}
public HttpHeaders getHeaders() {
return headers;
}