mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-02 11:15:03 +03:00
fix(mtproto): leave clients mtg cannot parse out of the generated config
One mtg-multi process serves every client of an MTProto inbound from a single TOML file and refuses the whole file over one value it cannot parse. InstanceFromInbound already guarded the ad tag for that reason but copied secret, quota and expiry as stored, so a malformed secret, a year-10000 expiry or a near-MaxInt64 quota on one client took the sidecar down for everyone on the inbound. A client whose secret mtg cannot parse is left out with a warning, and quota and expiry are capped at what mtg accepts.
This commit is contained in:
@@ -169,8 +169,9 @@ func GetManager() *Manager {
|
||||
// InstanceFromInbound derives a desired Instance from an mtproto inbound,
|
||||
// building one named secret per active client. Secrets are healed on save (see
|
||||
// normalizeMtprotoSecret) and by the migration, so they are read as-is here to
|
||||
// keep the fingerprint stable across reconciles. Returns false when the inbound
|
||||
// is not a usable mtproto inbound or has no active client secret to serve.
|
||||
// keep the fingerprint stable across reconciles; a client whose stored values
|
||||
// mtg could not parse is left out (see usableAdTag). Returns false when the
|
||||
// inbound is not a usable mtproto inbound or has no active client secret to serve.
|
||||
func InstanceFromInbound(ib *model.Inbound) (Instance, bool) {
|
||||
if ib == nil || ib.Protocol != model.MTProto {
|
||||
return Instance{}, false
|
||||
@@ -205,15 +206,15 @@ func InstanceFromInbound(ib *model.Inbound) (Instance, bool) {
|
||||
}
|
||||
secrets := make([]SecretEntry, 0, len(parsed.Clients))
|
||||
for _, c := range parsed.Clients {
|
||||
if !c.Enable || c.Secret == "" || c.Email == "" {
|
||||
if !c.Enable || c.Email == "" || !model.ValidMtprotoSecret(c.Secret) {
|
||||
continue
|
||||
}
|
||||
entry := SecretEntry{Name: c.Email, Secret: c.Secret, AdTag: usableAdTag(c.AdTag)}
|
||||
if c.TotalGB > 0 {
|
||||
entry.QuotaBytes = c.TotalGB
|
||||
entry.QuotaBytes = min(c.TotalGB, maxQuotaBytes)
|
||||
}
|
||||
if c.ExpiryTime > 0 {
|
||||
entry.ExpiresUnix = c.ExpiryTime / 1000
|
||||
entry.ExpiresUnix = min(c.ExpiryTime/1000, maxExpiresUnix)
|
||||
}
|
||||
secrets = append(secrets, entry)
|
||||
}
|
||||
@@ -253,6 +254,13 @@ func usableAdTag(tag string) string {
|
||||
return tag
|
||||
}
|
||||
|
||||
// The largest limits mtg parses: its byte parser overflows just short of
|
||||
// MaxInt64 and RFC 3339 ends with the year 9999. Larger stored values are capped.
|
||||
const (
|
||||
maxQuotaBytes = int64(9_000_000_000_000_000_000)
|
||||
maxExpiresUnix = int64(253402300799)
|
||||
)
|
||||
|
||||
// Ensure starts the mtg process for an instance, or restarts it when its
|
||||
// configuration changed. A no-op when the desired process is already running.
|
||||
func (m *Manager) Ensure(inst Instance) error {
|
||||
|
||||
Reference in New Issue
Block a user