Add SOCKS5 password protection for local proxy interface (RFC 1929)#3243
Add SOCKS5 password protection for local proxy interface (RFC 1929)#3243Copilot wants to merge 4 commits into
Conversation
Agent-Logs-Url: https://github.com/shadowsocks/shadowsocks-android/sessions/d496275b-6490-48b5-8dd9-acbbd50734ae Co-authored-by: madeye <627917+madeye@users.noreply.github.com>
Agent-Logs-Url: https://github.com/shadowsocks/shadowsocks-android/sessions/d496275b-6490-48b5-8dd9-acbbd50734ae Co-authored-by: madeye <627917+madeye@users.noreply.github.com>
madeye
left a comment
There was a problem hiding this comment.
Review
Adds optional RFC 1929 auth on the local SOCKS5 listener. I verified the integration points against the actual sources: shadowsocks-rust supports socks5_auth_config_path and the JSON shape matches (crates/shadowsocks-service/src/config.rs:1830, local/socks/config.rs:51), and the bundled badvpn tun2socks supports --username/--password and applies auth to both the TCP path and the UDP relay path (tun2socks.c:1185, SocksUdpGwClient.c:408). Referenced resources (preference_dialog_password, ic_settings_password) exist. The approach is sound, but there is one startup-breaking bug.
🔴 Critical: auth file path doesn't resolve — service fails to start when a password is set
The config gets a relative path: put("socks5_auth_config_path", "socks5_auth"). ss-local resolves it against its working directory, which is Core.deviceStorage.noBackupFilesDir (GuardedProcessPool.kt:54, i.e. /data/user_de/...). But the auth file is written next to configFile, and per BaseService.kt:244-245 the config root is app.noBackupFilesDir (/data/user/...) whenever the user is unlocked — the normal case on API ≥ 24. ss-local's Socks5AuthConfig::load_from_file error propagates with ?, so config loading fails and the process exits → crash loop / service start failure. The feature only works by accident in direct-boot mode, where the two directories coincide.
Fix: write the absolute path into the config: put("socks5_auth_config_path", authFile.absolutePath) (compute the file before building the JSON). This also keeps the auth file in credential-encrypted storage, which is strictly better for a secret.
🟡 Worth fixing
- Shared filename across instances. Both the main
ProxyInstanceand theudpFallbackinstance write the samesocks5_authfile and both delete it inshutdown(). Content is identical so it works, but it's fragile — use a per-instance name like"${configFile.name}_auth". - TV password field is plaintext.
tv/pref_main.xmluses a plainEditTextPreferencewithout a password dialog layout, so the password is shown in cleartext while typing (mobile'spreference_dialog_passwordlayout lives in the mobile module, so it would need a TV equivalent or moving the layout to core). configFile.parentFile ?: configFile.canonicalFile.parentFile— the fallback is dead code sinceconfigFileis always constructed with an absolute parent; simplify toconfigFile.parentFile.
🟢 Security notes (acceptable, but worth documenting)
- RFC 1929 sends credentials in cleartext. Combined with "Share over LAN" (
listenAddress = 0.0.0.0), the password traverses the LAN unencrypted. Fine for the stated threat model (blocking other local apps), but the summary string could note it's not protection on untrusted networks. - The password appears on tun2socks' command line. Other apps can't read it on modern Android (
/procis hidepid), so low risk; tun2socks also supports--password-fileif you want defense in depth. - The local DNS relay listener (
portLocalDns) remains unauthenticated — other apps can still use it. Probably fine, but it slightly undercuts the "no unauthorized use" claim in the description.
Verdict
Request changes: the relative-path bug breaks service startup whenever a password is actually set on an unlocked device. The fix is a one-liner; the rest is polish.
Fixed in a3c7f58:
|
|
I prefer not exposing a local port by default as a better mitigation. Use a unix local socket for IPC instead. |
Any app on the device can use the local SOCKS5 proxy (default port 1080) without authentication, enabling unauthorized traffic routing and potential VPN IP leakage. This adds optional RFC 1929 username/password authentication to the local SOCKS5 interface.
How it works
ss-localis configured with asocks5_auth_config_pathpointing to a generated auth config file (username:shadowsocks, password: user-configured)tun2socksreceives--username/--passwordso VPN mode continues to work transparentlyChanges
Constants.kt/DataStore.kt:socksPasswordkey and property backed bypublicStoreProxyInstance.kt: Writessocks5_authJSON config file and addssocks5_auth_config_pathto the local SOCKS5 listener config when password is set; cleans up on shutdownVpnService.kt: Passes--username shadowsocks --password <pwd>to tun2socks when password is setpref_global.xml/pref_main.xml:EditTextPreference(password dialog) for the new settingGlobalSettingsPreferenceFragment.kt/MainPreferenceFragment.kt: Password preference disabled while service is runningAuth config format written to
socks5_auth{ "password": { "users": [{ "user_name": "shadowsocks", "password": "<user-configured>" }] } }Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.foojay.io/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xmx64m -Xms64m -Dorg.gradle.appname=gradlew -classpath \"\" -jar /home/REDACTED/work/shadowsocks-android/shadowsocks-android/gradle/wrapper/gradle-wrapper.jar :core:compileDebugKotlin /main/java/com/g--norc /main/java/com/g--noprofile /main/java/com/github/shadowsocks/tv/App.kt rc/s�� /src/test/java/com/github/shadowsocks/plugin/PluginOptionsTest.kt /src/main/java/com/github/shadowsocks/plugin/Utils.kt /src/main/java/com/github/shadowsocks/plugin/AlertDialogFragment.kt /src/main/java/cgit /src/main/java/cls-files /src/main/java/c--exclude-standard /src/main/java/c--others(dns block)/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xmx64m -Xms64m -Dorg.gradle.appname=gradlew -classpath \"\" -jar /home/REDACTED/work/shadowsocks-android/shadowsocks-android/gradle/wrapper/gradle-wrapper.jar :core:compileDebugKotlin -Porg.gradle.java.installations.auto-provision=false om/github/shadowsocks/plugin/HelpCallback.kt om/github/shadowsocks/plugin/PluginContract.kt om/g�� om/github/shadowsocks/plugin/PluginOptions.kt om/github/shadowsocks/plugin/HelpActivity.kt /src/main/res/values-ru/strings.xml /src/main/res/vaiptables /src/main/res/va-w /src/main/res/va-t /src/main/res/vasecurity(dns block)/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xmx64m -Xms64m -Dorg.gradle.appname=gradlew -classpath \"\" -jar /home/REDACTED/work/shadowsocks-android/shadowsocks-android/gradle/wrapper/gradle-wrapper.jar :core:compileDebugKotlin --no-daemon -Dorg.gradle.java.home=/usr/lib/jvm/temurin-17-jdk-amd64(dns block)If you need me to access, download, or install something from one of these locations, you can either: