Prevent invalid subscription responses from overwriting config.yaml - #818
Open
Andyduck-ops wants to merge 1 commit into
Open
Prevent invalid subscription responses from overwriting config.yaml#818Andyduck-ops wants to merge 1 commit into
Andyduck-ops wants to merge 1 commit into
Conversation
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.
Problem
When updating a profile, CMFA assumes that every response body is a valid Clash configuration.
If a subscription server returns an error page or informational text instead of YAML, CMFA currently:
config.yamlwith the response body;This produces a misleading YAML error such as:
More importantly, the previously valid configuration has already been replaced by the invalid response.
Root cause
openUrlreturned the response body regardless of the HTTP status, and the configuration download path passed that body directly towriteFile.Configuration validation only happened later in
UnmarshalAndPatch, afterconfig.yamlhad already been overwritten.The original YAML involved in the reported case parses successfully with Mihomo. The parsing error was caused by a non-configuration response body from the subscription server, not by CRLF or flow-style YAML syntax.
Reproduction
Use a subscription endpoint that returns either:
检测到不受支持的客户端.With an existing valid
config.yaml, trigger a forced profile update.Before this change, CMFA writes the response body to
config.yamland then reports a YAML unmarshalling error.Fix
mihomo/config.UnmarshalRawConfigbefore writing it.config.yamlwhen the downloaded content is not a valid configuration.Tests
Added regression coverage for:
The tests were formatted and added to the affected Go package. Full local execution was blocked by unavailable cached build dependencies, so CI verification is still required.