XTLS/Xray-core · error

illegal domain rule:

Error message

illegal domain rule: 

What it means

ParseDomainRule wraps any failure from parseGeoSiteRule or parseCustomDomainRule for a single domain rule string. The full raw rule is echoed in the message and the base error carries the concrete cause (syntax error, empty file/code/attr, bad regex, etc.).

Source

Thrown at common/geodata/rule_parser.go:156

	}

	prefix := 0
	for _, ext := range [...]string{"ext:", "ext-domain:", "ext-site:"} {
		if strings.HasPrefix(r, ext) {
			prefix = len(ext)
			break
		}
	}

	var rule isDomainRule_Value
	var err error
	if prefix > 0 {
		rule, err = parseGeoSiteRule(r[prefix:])
	} else {
		rule, err = parseCustomDomainRule(r, defaultType)
	}
	if err != nil {
		return nil, errors.New("illegal domain rule: ", r).Base(err)
	}
	return &DomainRule{Value: rule}, nil
}

func ParseDomainRules(rules []string, defaultType Domain_Type) ([]*DomainRule, error) {
	var domainRules []*DomainRule

	for i, r := range rules {
		if strings.HasPrefix(r, "geosite:") {
			r = "ext:" + DefaultGeoSiteDat + ":" + r[len("geosite:"):]
		}

		prefix := 0
		for _, ext := range [...]string{"ext:", "ext-domain:", "ext-site:"} {
			if strings.HasPrefix(r, ext) {
				prefix = len(ext)
				break
			}

View on GitHub (pinned to 7d214f8b09)

Solutions

  1. Read the base error; fix the specific sub-problem (missing code after geosite:, unclosed regex, etc.).
  2. Use supported forms: plain domain, "domain:", "full:", "keyword:", "regexp:", "geosite:CODE", "ext:FILE:CODE[@attrs]".
  3. Validate config with `xray run -test -c config.json`.

Example fix

// before
"domain": ["geosite:"]

// after
"domain": ["geosite:cn"]
Defensive patterns

Strategy: validation

Validate before calling

if _, err := geodata.ParseDomainRule(rule, Domain_Full); err != nil {
    return fmt.Errorf("config rejected: bad domain rule %q: %w", rule, err)
}

Try / catch

Wrap ParseDomainRule calls at config-load time and abort startup with the echoed rule string rather than retrying at runtime.

Prevention

When it happens

Trigger: Domain rules like "geosite:", "ext:gs.dat:", "regex:[unclosed", "dotless:a.b", or an invalid punycode/IDN string.

Common situations: Typos in the domain array of routing rules; mixing IP syntax into domain rules; unsupported attr suffixes like "geosite:cn@".

Related errors


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/aba6baf5c5ac4839. Report an issue: GitHub.