Skip to content

fix: validate package names during clipboard import in per-app proxy - #123

Open
Vim-01 wants to merge 1 commit into
throneproj:mainfrom
Vim-01:fix/per-app-clipboard-validation
Open

Vim-01 wants to merge 1 commit into
throneproj:mainfrom
Vim-01:fix/per-app-clipboard-validation

Conversation

@Vim-01

@Vim-01 Vim-01 commented Oct 30, 2026

Copy link
Copy Markdown

Summary

Fixes clipboard import in per-app proxy incorrectly parsing URLs and arbitrary text as application package names (#113).

Root Cause

In v2.0.4, action_import_clipboard split clipboard content by newlines and saved lines directly into DataStore.individual without verifying whether each string conforms to Android package naming rules. If a URL (e.g. https://www.gstatic.com/generate_204) was in the clipboard, it was saved as an extra uninstalled app and enabled. Upon starting the VPN:

  • ConfigGenerator included the URL into tun.include_package.
  • VpnService.Builder.addAllowedApplication() threw PackageManager.NameNotFoundException, adding 0 apps to the OS tunnel builder (causing OS to route all apps into the tun).
  • sing-box dropped all packets because no traffic matched the non-existent URL package name, cutting off internet access.

Solution

  • Introduce strict AOSP package name validation via PackageCache.isValidPackageName() (requiring at least two dot-separated segments starting with ASCII letters, and allowing framework "android").
  • Validate clipboard entries in AppManagerActivity and AppListActivity; abort and show error snackbar without overwriting stored configuration when no valid packages are present.
  • Implement self-healing in AppManagerActivity.initProxiedUids() to automatically purge invalid legacy entries from DataStore.individual.
  • Filter perAppPackages in SettingsMapper to prevent invalid entries from reaching core configs.
  • Safeguard VpnService.addAllowedApplication against OEM runtime exceptions.
  • Add unit tests covering package validation regex, mixed clipboard parsing, and config self-healing.

In v2.0.4, importing from clipboard accepted any non-empty string without
verifying whether it constitutes a valid Android package name. If a URL
or arbitrary text was in the clipboard, it was imported into DataStore.individual
as an extra selected package. This caused sing-box's include_package rule to
receive invalid package strings, while Android VpnService threw
NameNotFoundException on openTun(), breaking VPN routing and leaving the
selection corrupted.

- Validate package names against AOSP package naming format (and allow framework "android")
  via PackageCache.isValidPackageName().
- Reject invalid clipboard payloads in AppManagerActivity and AppListActivity without
  overwriting existing user proxy configuration.
- Automatically purge corrupt entries from DataStore.individual in initProxiedUids()
  and filter perAppPackages in SettingsMapper to prevent TUN startup failures.
- Safeguard VpnService against unhandled OEM exceptions during addAllowedApplication.
- Add unit tests verifying regex conformance, clipboard extraction, and config self-healing.

Fixes throneproj#113
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant