Skip to content
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

HTTPS URLs are no valid HTTP(S) proxy addresses #1269

Closed
lenerd opened this issue Feb 8, 2025 · 5 comments · Fixed by #1276
Closed

HTTPS URLs are no valid HTTP(S) proxy addresses #1269

lenerd opened this issue Feb 8, 2025 · 5 comments · Fixed by #1276
Assignees
Labels
Milestone

Comments

@lenerd
Copy link
Contributor

lenerd commented Feb 8, 2025

Hello,

I am trying to configure an HTTPS proxy such that syncthing's requests to https://{discovery,relays}.syncthing.net are proxied. On my computer, I achieve this by setting the https_proxy environment variable. When I try the same in the android app via Experimental -> HTTP(S) proxy, I get an error message, that the "Input violates proxy syntax".

In the corresponding code, the regex ^http://.*:\\d{1,5}$ only supports HTTP URLs. Is there a specific reason for this restriction? I would like to use a URL of the form https://user:[email protected]:1337 to connect to my proxy server.

private boolean handleHttpProxyPreferenceChange(Preference preference, String newValue) {
// Valid input is either a proxy address or an empty field to disable the proxy.
if (newValue.equals("")) {
preference.setSummary(getString(R.string.do_not_use_proxy) + " " + getString(R.string.generic_example) + ": " + getString(R.string.http_proxy_address_example));
return true;
} else if (newValue.matches("^http://.*:\\d{1,5}$")) {
preference.setSummary(getString(R.string.use_proxy) + " " + newValue);
return true;
} else {
Toast.makeText(getActivity(), R.string.toast_invalid_http_proxy_address, Toast.LENGTH_SHORT)
.show();
return false;
}
}

@Catfriend1
Copy link
Owner

Does Android Linux support:

https://user:[email protected]:1337

?

@lenerd
Copy link
Contributor Author

lenerd commented Feb 10, 2025

Good question. I guess it depends what is meant by that. Take the following with a grain of salt, since I am not very familiar with Android internals.

When trying to configure a proxy in the Wi-Fi settings, GrapheneOS indeed only allows me to specify a hostname and a port. Apparently there are/were some versions of Android that also allow to specify credentials. In any way, it depends on the applications to support and honor this setting.

Regarding syncthing(-android): When the HTTP(S) Proxy setting is non-empty, syncthing-android sets the environment variables http_proxy and https_proxy accordingly, and then runs syncthing. Syncthing picks up these settings when it creates the HTTPS connections by calling http.ProxyFromEnvironment (cf. syncthing/syncthing/pull/2375). So it seems that the proxy handling happens withing the Go standard library. Assuming the syncthing code that is run on Android is the same that runs when installing syncthing on a normal Linux computer, I do not see why it should not work.

If I manage to compile syncthing-android myself, I could make the regex less restrictive and try to see if it works.

@Catfriend1
Copy link
Owner

I could do that for you, but then I'd need you standby for feedback to verify the change working correctly. Compiling using the batch / py scripts is relatively easy. Install Android studio , python, git tools, run setenv.cmd and build . :)

@lenerd
Copy link
Contributor Author

lenerd commented Feb 10, 2025

I managed to build an APK with a patched regular expression (9a680a3). With the "HTTP(S) proxy" option in syncthing set to an HTTPS URL pointing to my server, I could observe successful connections from the app to the *.syncthing.net domains.

@Catfriend1
Copy link
Owner

Wew, congrats. So we have a verified change. Feel free to PR that line and get the credit of contributing 👍🤗

lenerd added a commit to lenerd/syncthing-android that referenced this issue Feb 11, 2025
Make the regular expression less restrictive such that not only
`http://, but also `https://` URLs are allowed.

Fixes Catfriend1#1269
lenerd added a commit to lenerd/syncthing-android that referenced this issue Feb 11, 2025
Make the regular expression used to check the validity of the "HTTP(S)
proxy" setting less restrictive such that not only `http://, but also
`https://` URLs are allowed.

Fixes Catfriend1#1269
@Catfriend1 Catfriend1 added bug and removed pr-welcome labels Feb 11, 2025
@Catfriend1 Catfriend1 added this to the v1.29.3 milestone Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants