mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-18 19:15:03 +03:00
fix(sub): treat external subscription providers as untrusted input
A client's external subscription is fetched from a third party on every subscriber refresh, and the fetcher trusted it more than its siblings: - it dialled any address, redirects included; it now goes through the SSRF guard like the outbound subscription and remote routing fetchers; - it forwarded any line containing "://"; it now keeps only server share links, so app deeplinks and plain URLs never reach the subscriber's app; - it bounded the body but not the link count (now 1000) or the headers (now 64 KiB), and stored the raw error, URL included, on every row; the stored error is now host-only and at most 1 KiB. The link parser also refuses links that nest JSON past 16 levels, since the JSON subscription pretty-prints it at quadratic cost, and external configs are marshalled compactly until the final, single indent pass.
This commit is contained in:
@@ -131,9 +131,37 @@ func ParseLink(link string) (*ParseResult, error) {
|
||||
return nil, err
|
||||
}
|
||||
dropHostLocalKeys(res.Outbound)
|
||||
if !nestsWithin(map[string]any(res.Outbound), maxOutboundDepth) {
|
||||
return nil, fmt.Errorf("link nests JSON deeper than %d levels", maxOutboundDepth)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// maxOutboundDepth bounds the JSON a link can nest into its outbound (the deepest real shape,
|
||||
// an xhttp download stream's finalmask, is about 11): pretty-printing costs depth squared.
|
||||
const maxOutboundDepth = 16
|
||||
|
||||
func nestsWithin(v any, depth int) bool {
|
||||
if depth < 0 {
|
||||
return false
|
||||
}
|
||||
switch v := v.(type) {
|
||||
case map[string]any:
|
||||
for _, child := range v {
|
||||
if !nestsWithin(child, depth-1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
case []any:
|
||||
for _, child := range v {
|
||||
if !nestsWithin(child, depth-1) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func parseLinkByScheme(link string) (*ParseResult, error) {
|
||||
switch {
|
||||
case strings.HasPrefix(link, "vmess://"):
|
||||
|
||||
Reference in New Issue
Block a user