fix: handle shell-safe URLs and preserve custom subscription DNS - #300
Open
MicroMilo wants to merge 1 commit into
Open
fix: handle shell-safe URLs and preserve custom subscription DNS#300MicroMilo wants to merge 1 commit into
MicroMilo wants to merge 1 commit into
Conversation
MicroMilo
marked this pull request as ready for review
August 5, 2026 06:34
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this solve?
This PR addresses two independent failure points that can appear in the same subscription onboarding flow.
1. Shell parsing can truncate subscription URLs
Subscription URLs commonly contain
&, for example:When such a URL is passed to
clash addwithout quotes, Bash treats each&as a background-command separator beforeclashreceives the arguments. Only the prefix reachesclash add, the subscription name is not saved, and a subsequentclash use <name>reports that the subscription does not exist.The README now shows both safe forms:
2. Runtime normalization can overwrite a subscription's DNS listener
Some providers publish a local DNS forwarder such as:
The current normalization path always replaces
dns.listenwithCLASH_DNS_PORT. That can leaveproxy-server-nameserverpointing at a port that is no longer listening, so the subscription fails after it has been added successfully.This PR adds the opt-in setting
CLASH_PRESERVE_DNS_LISTEN=trueto preserve the subscription's completedns.listenvalue. A preserved port is never silently reassigned: conflicts produce a clear error instead.Compatibility
CLASH_PRESERVE_DNS_LISTENdefaults tofalse, so existing installations keep their current behavior.dns.listenfalls back toCLASH_DNS_PORT.Refs #295
Validation
bash -n scripts/core/config.sh scripts/core/clashctl.sh scripts/dev/check-runtime-config-normalization.shgit diff --checkbash scripts/dev/check-runtime-config-normalization.shbash scripts/dev/check-clash-command-entry.shbash scripts/dev/check-sub-update-compat.shbash scripts/dev/check-text-encoding.sh