Class GuardRuleParser
java.lang.Object
org.frontcache.guard.GuardRuleParser
Parses one line of guard-rules.conf into a
GuardRule.
Line format (see docs/guard-getting-started.md):
<name> | <predicate> ; <predicate> ... | <action> [| dry-run] [| on-error=allow] [| trap]
A rate: predicate is moved to the END of its condition here (see
parseCondition(String, String)); a rule may hold at most one.
Actions:
allow
reject:<status> [body]
redirect:<301|302|303|307|308> <target>
challenge <provider> [else <reject:...|redirect:...>]
Every rejection is reported as a GuardConfigException so the caller can skip that single
line and keep the rest of the file working.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe flag anallowrule naming a plugin's predicate (ext:) must carry: its author has accepted that when the predicate has no answer - the plugin threw, is over its budget, or is absent - the rule does not match, so the exemption does not apply to that request.static final StringThe flag of a honeypot rule - a path no visitor is ever sent to, whose fetch identifies the client: the rule matches a client's request only, never an include, and its log line names the address this node resolved (GuardRule.logReason(RequestContext, boolean)). -
Constructor Summary
ConstructorsConstructorDescriptionGuardRuleParser(Set<String> allowedRedirectHosts) GuardRuleParser(Set<String> allowedRedirectHosts, VisitorTypes visitorTypes) -
Method Summary
-
Field Details
-
ON_ERROR_ALLOW
The flag anallowrule naming a plugin's predicate (ext:) must carry: its author has accepted that when the predicate has no answer - the plugin threw, is over its budget, or is absent - the rule does not match, so the exemption does not apply to that request.- See Also:
-
TRAP
The flag of a honeypot rule - a path no visitor is ever sent to, whose fetch identifies the client: the rule matches a client's request only, never an include, and its log line names the address this node resolved (GuardRule.logReason(RequestContext, boolean)). Refused on anallowrule, which records nothing.- See Also:
-
-
Constructor Details
-
GuardRuleParser
-
GuardRuleParser
- Parameters:
visitorTypes- whatclient-type:is checked against; null - the node's loaded vocabulary, read when each line is parsed. A validator with no node passes the bots.conf declarations.
-
-
Method Details
-
parse
-
splitFields
Splits a rule line into itsname | condition | action [| flag]fields. Public because bots.conf uses the same line format and must split it the same way - seeBotRuleParser. One splitter, so the alternation bug below cannot be re-introduced in the second file. The obviousline.split("\\|")is wrong, and was:|is also regex alternation, so a perfectly ordinary predicate likeuri~^/(recent|user)-contributions\.htmgot shredded at the alternation and the rule was refused at load time as "invalid regex ... Unclosed group". The rest of the file kept working, which is what made it invisible: on a production node this silently disabled 5 of 19 rules - and they were every anti-scraper redirect, i.e. exactly the rules whose absence costs nothing until a flood arrives. So a|separates fields only where a regex cannot be using it: outside any(...)group, outside any[...]character class, and not backslash-escaped. Fields come back byte-identical - nothing is unescaped - so\|still reads as a literal pipe to the regex engine, and a top-level alternation is written the way it already was, in parentheses.
-