Skip to content

Commit 6e99928

Browse files
committed
Exclude ourselves from the VPN, to avoid pings becoming recursive
Our ping proxy uses isReachable, which doesn't give us an explicit socket, so can't be protected and kept out of the VPN. Without this (or filtering to just the ping app, as I had been testing before...) pings result in a ping back into our own VPN, and the whole app crashes in short order.
1 parent 1ba0420 commit 6e99928

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/src/main/java/tech/httptoolkit/android/ProxyVpnService.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,18 @@ class ProxyVpnService : VpnService(), IProtectSocket {
149149
.addAddress(VPN_IP_ADDRESS, 32)
150150
.addRoute(ALL_ROUTES, 0)
151151
.apply {
152+
// We exclude ourselves from interception, so we can still make network requests
153+
// separately, primarily because otherwise pinging with isReachable is recursive.
154+
val httpToolkitPackage = packageName
155+
152156
// For some reason, with Genymotion the whole device crashes if we intercept
153157
// blindly, but intercepting every single application explicitly is fine.
154158
if (isGenymotion) {
155-
packageNames.forEach { name -> addAllowedApplication(name) }
159+
packageNames.forEach { name ->
160+
if (name != httpToolkitPackage) addAllowedApplication(name)
161+
}
162+
} else {
163+
addDisallowedApplication(httpToolkitPackage)
156164
}
157165
}
158166
.setSession(getString(R.string.app_name))

0 commit comments

Comments
 (0)