Rules
Rule Set

Rule Sets

The rule set feature allows referencing a large number of rules with low resource consumption and supports silent updates in the background without reloading Stash. To use rule sets, you need to declare them under rule-providers, and then reference the sets under rules.

rule-providers:
  proxy-domain:
    behavior: domain # Using domain-type rule sets can improve matching efficiency
    format: yaml # Use YAML format for rule sets
    url: https://cdn.jsdelivr.net/gh/Loyalsoldier/clash-rules@release/proxy.txt
    interval: 86400
 
  cn-cidr:
    behavior: ipcidr # Using ipcidr-type rule sets can improve matching efficiency
    format: text # Use text format for rule sets
    url: https://cdn.jsdelivr.net/gh/17mon/china_ip_list@master/china_ip_list.txt
    interval: 86400
 
rules:
  - RULE-SET,proxy-domain,Proxy
  - RULE-SET,cn-cidr,DIRECT,no-resolve # ipcidr-type rule sets support the no-resolve parameter

If a remote rule set requires authentication, or if the server expects specific request headers such as Accept or User-Agent, configure headers on the rule provider. Stash sends these headers when updating the remote rule set.

rule-providers:
  proxy-domain:
    behavior: domain
    format: yaml
    url: https://example.com/rules.yaml
    interval: 86400
    headers:
      Authorization: Bearer your-token
      Accept: application/yaml

Values under headers can be either a single string or an array of strings for multi-value request headers:

rule-providers:
  proxy-domain:
    behavior: domain
    format: yaml
    url: https://example.com/rules.yaml
    interval: 86400
    headers:
      Accept:
        - application/yaml
        - text/plain

If the URL already contains a username and password, such as https://user:password@example.com/rules.yaml, Stash uses the URL credentials to generate Basic Auth. In that case, it overrides Authorization configured in headers.

Stash supports various rule set formats, each supporting different content types and exhibiting different resource usage:

BehaviorFormatSupported ContentExampleMatching PerformanceMemory Usage
domainyamlDomains/Domain WildcardsLink (opens in a new tab)ExcellentLow
domaintextDomains/Domain WildcardsLink (opens in a new tab)ExcellentLow
ipcidryamlIPv4/IPv6 collections, CIDR formatLink (opens in a new tab)ExcellentLow
ipcidrtextIPv4/IPv6 collections, CIDR formatLink (opens in a new tab)ExcellentLow
classicalyamlAny rule typeLink (opens in a new tab)AverageAverage
classicaltextAny rule typeLink (opens in a new tab)AverageAverage
💡

Rule sets of type domain(-text) and ipcidr(-text) are specially compressed and optimized for a large amount of data. It is recommended to prioritize these when there are a lot of rule entries.

💡

Stash also supports using MRS format rule sets, currently supporting rule sets with behavior as domain and ipcidr.