edgeprotect

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 2 Imported by: 3 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package edgeprotect recognizes when the answer to a request came from an edge protection (a CDN or WAF) in place of the service: a challenge page, a block page, a rate limit, or only the edge fronting real content.

The decision is an observation about the edge, never about the service behind it: a caller keeps the service's last real response and facts, and records the verdict beside them. A challenge or a block needs a marker that belongs to one vendor (a vendor header, a vendor error page); a bare 403 or 503 is the origin's own answer and is never read as an edge decision. An address range or a fronting header alone gives Fronted, never Challenged or Blocked.

Classify is pure and bounded: it reads at most MaxBody bytes of the body, MaxTitle of the title and MaxHeaderValue of each header value, so a hostile response cannot cost more than a fixed amount of work. It never solves a challenge, never sends a request and never changes how a request is made: the answer to a scan that an edge stops is "the edge stopped it", and what follows (allowlisting the scanner at the edge, scanning the origin where it is proven to be the tenant's) is cooperative.

The signature table is data (Rules) so a newer table can be shipped without a new release of the code that reads it; DefaultRules is the built-in floor.

The package has no dependency outside the standard library, so a platform and a sensor read the same signature table without depending on each other.

Index

Constants

View Source
const (
	Cloudflare = "cloudflare"
	CloudFront = "cloudfront"
	Akamai     = "akamai"
	Fastly     = "fastly"
	AzureFD    = "azure_front_door"
	Imperva    = "imperva"
	F5         = "f5"
	DataDome   = "datadome"
	PerimeterX = "perimeterx"
	Sucuri     = "sucuri"
)

Vendors the built-in rules know.

View Source
const (
	MaxBody        = 16 << 10
	MaxTitle       = 512
	MaxHeaderValue = 1024
)

Bounds of what Classify reads.

Variables

View Source
var DefaultRules = []Rule{

	{ID: "cloudflare.cf-mitigated", Vendor: Cloudflare, State: Challenged,
		All: []Marker{{Header: "Cf-Mitigated", HeaderContains: "challenge"}}},
	{ID: "cloudflare.managed-challenge-page", Vendor: Cloudflare, State: Challenged, Status: []int{403, 429, 503},
		All: []Marker{{Title: "just a moment"}, {Body: "challenge-platform"}}},
	{ID: "cloudflare.block-page", Vendor: Cloudflare, State: Blocked, Status: []int{403},
		All: []Marker{{Title: "attention required"}, {Body: "cloudflare"}}},
	{ID: "cloudflare.block-page-sorry", Vendor: Cloudflare, State: Blocked, Status: []int{403},
		All: []Marker{{Body: "sorry, you have been blocked"}, {Body: "cloudflare"}}},
	{ID: "cloudflare.firewall-1020", Vendor: Cloudflare, State: Blocked, Status: []int{403},
		All: []Marker{{Body: "error code: 1020"}, {Body: "cloudflare"}}},
	{ID: "cloudflare.ip-banned", Vendor: Cloudflare, State: Blocked, Status: []int{403},
		All: []Marker{{Body: "cloudflare ray id"}, {Body: "has banned your ip address"}}},
	{ID: "cloudflare.browser-signature-1010", Vendor: Cloudflare, State: Blocked, Status: []int{403},
		All: []Marker{{Body: "error code: 1010"}, {Body: "cloudflare"}}},
	{ID: "cloudflare.rate-limit-1015", Vendor: Cloudflare, State: RateLimited, Status: []int{429},
		All: []Marker{{Body: "error code: 1015"}, {Body: "cloudflare"}}},
	{ID: "cloudflare.server", Vendor: Cloudflare, State: Fronted,
		All: []Marker{{Header: "Server", HeaderContains: "cloudflare"}}},
	{ID: "cloudflare.cf-ray", Vendor: Cloudflare, State: Fronted,
		All: []Marker{{Header: "Cf-Ray"}}},

	{ID: "aws-waf.challenge", Vendor: CloudFront, State: Challenged,
		All: []Marker{{Header: "X-Amzn-Waf-Action", HeaderContains: "challenge"}}},
	{ID: "aws-waf.captcha", Vendor: CloudFront, State: Challenged,
		All: []Marker{{Header: "X-Amzn-Waf-Action", HeaderContains: "captcha"}}},
	{ID: "cloudfront.waf-block", Vendor: CloudFront, State: Blocked, Status: []int{403},
		All: []Marker{{Header: "X-Cache", HeaderContains: "error from cloudfront"}, {Body: "request blocked"}}},
	{ID: "cloudfront.rate-limit", Vendor: CloudFront, State: RateLimited, Status: []int{429},
		All: []Marker{{Header: "X-Cache", HeaderContains: "error from cloudfront"}}},
	{ID: "cloudfront.cf-id", Vendor: CloudFront, State: Fronted,
		All: []Marker{{Header: "X-Amz-Cf-Id"}}},
	{ID: "cloudfront.cf-pop", Vendor: CloudFront, State: Fronted,
		All: []Marker{{Header: "X-Amz-Cf-Pop"}}},
	{ID: "cloudfront.via", Vendor: CloudFront, State: Fronted,
		All: []Marker{{Header: "Via", HeaderContains: "(cloudfront)"}}},

	{ID: "akamai.sec-cpt-challenge", Vendor: Akamai, State: Challenged, Status: []int{200, 403, 429},
		All: []Marker{{Body: "sec-if-cpt-container"}}},
	{ID: "akamai.access-denied", Vendor: Akamai, State: Blocked, Status: []int{403},
		All: []Marker{{Title: "access denied"}, {Body: "reference&#32;#18."}}},
	{ID: "akamai.access-denied-plain", Vendor: Akamai, State: Blocked, Status: []int{403},
		All: []Marker{{Title: "access denied"}, {Body: "reference #18."}}},
	{ID: "akamai.access-denied-ghost", Vendor: Akamai, State: Blocked, Status: []int{403},
		All: []Marker{{Header: "Server", HeaderContains: "akamaighost"}, {Title: "access denied"}, {Body: "reference"}}},
	{ID: "akamai.rate-limit", Vendor: Akamai, State: RateLimited, Status: []int{429},
		All: []Marker{{Header: "Server", HeaderContains: "akamaighost"}}},
	{ID: "akamai.ghost", Vendor: Akamai, State: Fronted,
		All: []Marker{{Header: "Server", HeaderContains: "akamaighost"}}},
	{ID: "akamai.x-akamai", Vendor: Akamai, State: Fronted,
		All: []Marker{{HeaderPrefix: "X-Akamai-"}}},
	{ID: "akamai.bot-cookie", Vendor: Akamai, State: Fronted,
		All: []Marker{{Cookie: "ak_bmsc"}}},

	{ID: "fastly.waf-block", Vendor: Fastly, State: Blocked, Status: []int{406},
		All: []Marker{{Header: "X-Served-By", HeaderContains: "cache-"}, {Body: "not acceptable"}}},
	{ID: "fastly.rate-limit", Vendor: Fastly, State: RateLimited, Status: []int{429},
		All: []Marker{{Header: "X-Served-By", HeaderContains: "cache-"}}},
	{ID: "fastly.request-id", Vendor: Fastly, State: Fronted,
		All: []Marker{{Header: "X-Fastly-Request-Id"}}},
	{ID: "fastly.served-by", Vendor: Fastly, State: Fronted,
		All: []Marker{{Header: "X-Served-By", HeaderContains: "cache-"}, {Header: "X-Cache"}}},

	{ID: "azure-fd.waf-block", Vendor: AzureFD, State: Blocked, Status: []int{403},
		All: []Marker{{Header: "X-Azure-Ref"}, {Body: "the request is blocked"}}},
	{ID: "azure-fd.rate-limit", Vendor: AzureFD, State: RateLimited, Status: []int{429},
		All: []Marker{{Header: "X-Azure-Ref"}}},
	{ID: "azure-fd.ref", Vendor: AzureFD, State: Fronted,
		All: []Marker{{Header: "X-Azure-Ref"}}},

	{ID: "imperva.incident-block", Vendor: Imperva, State: Blocked,
		All: []Marker{{Body: "request unsuccessful. incapsula incident id"}}},
	{ID: "imperva.interruption", Vendor: Imperva, State: Challenged,
		All: []Marker{{Title: "pardon our interruption"}}},
	{ID: "imperva.js-interstitial", Vendor: Imperva, State: Challenged, MaxBodyLen: 4096,
		All: []Marker{{Header: "X-Iinfo"}, {Body: "_incapsula_resource"}}},
	{ID: "imperva.rate-limit", Vendor: Imperva, State: RateLimited, Status: []int{429},
		All: []Marker{{Header: "X-Iinfo"}}},
	{ID: "imperva.x-iinfo", Vendor: Imperva, State: Fronted,
		All: []Marker{{Header: "X-Iinfo"}}},
	{ID: "imperva.x-cdn", Vendor: Imperva, State: Fronted,
		All: []Marker{{Header: "X-Cdn", HeaderContains: "imperva"}}},
	{ID: "imperva.x-cdn-incapsula", Vendor: Imperva, State: Fronted,
		All: []Marker{{Header: "X-Cdn", HeaderContains: "incapsula"}}},
	{ID: "imperva.session-cookie", Vendor: Imperva, State: Fronted,
		All: []Marker{{Cookie: "incap_ses_"}}},
	{ID: "imperva.visitor-cookie", Vendor: Imperva, State: Fronted,
		All: []Marker{{Cookie: "visid_incap_"}}},

	{ID: "f5.rejected", Vendor: F5, State: Blocked,
		All: []Marker{{Body: "the requested url was rejected"}, {Body: "support id"}}},
	{ID: "f5.bigip-server", Vendor: F5, State: Fronted,
		All: []Marker{{Header: "Server", HeaderContains: "bigip"}}},
	{ID: "f5.bigip-cookie", Vendor: F5, State: Fronted,
		All: []Marker{{Cookie: "bigipserver"}}},
	{ID: "f5.ts-cookie", Vendor: F5, State: Fronted,
		All: []Marker{{Cookie: "ts01"}}},

	{ID: "datadome.challenge-header", Vendor: DataDome, State: Challenged,
		All: []Marker{{Body: "captcha-delivery.com"}, {Header: "X-Datadome"}}},
	{ID: "datadome.challenge-cookie", Vendor: DataDome, State: Challenged,
		All: []Marker{{Body: "captcha-delivery.com"}, {Cookie: "datadome"}}},
	{ID: "datadome.block", Vendor: DataDome, State: Blocked, Status: []int{403}, MaxBodyLen: 8192,
		All: []Marker{{Cookie: "datadome"}}},
	{ID: "datadome.header", Vendor: DataDome, State: Fronted,
		All: []Marker{{Header: "X-Datadome"}}},
	{ID: "datadome.cookie", Vendor: DataDome, State: Fronted,
		All: []Marker{{Cookie: "datadome"}}},

	{ID: "perimeterx.captcha", Vendor: PerimeterX, State: Challenged,
		All: []Marker{{Body: "px-captcha"}, {Body: "_pxappid"}}},
	{ID: "perimeterx.block-title", Vendor: PerimeterX, State: Blocked, Status: []int{403}, MaxBodyLen: 16384,
		All: []Marker{{Cookie: "_px"}, {Title: "access to this page has been denied"}}},
	{ID: "perimeterx.block-body", Vendor: PerimeterX, State: Blocked, Status: []int{403}, MaxBodyLen: 16384,
		All: []Marker{{Cookie: "_px"}, {Body: "access to this page has been denied"}}},
	{ID: "perimeterx.hd-cookie", Vendor: PerimeterX, State: Fronted,
		All: []Marker{{Cookie: "_pxhd"}}},
	{ID: "perimeterx.vid-cookie", Vendor: PerimeterX, State: Fronted,
		All: []Marker{{Cookie: "_pxvid"}}},

	{ID: "sucuri.block-id", Vendor: Sucuri, State: Blocked, Status: []int{403},
		All: []Marker{{Header: "X-Sucuri-Id"}, {Title: "sucuri website firewall"}}},
	{ID: "sucuri.block-server", Vendor: Sucuri, State: Blocked, Status: []int{403},
		All: []Marker{{Header: "Server", HeaderContains: "sucuri"}, {Title: "sucuri website firewall"}}},
	{ID: "sucuri.id", Vendor: Sucuri, State: Fronted,
		All: []Marker{{Header: "X-Sucuri-Id"}}},
	{ID: "sucuri.server", Vendor: Sucuri, State: Fronted,
		All: []Marker{{Header: "Server", HeaderContains: "sucuri"}}},
}

DefaultRules is the built-in signature table. Markers are short signs a vendor's own edge puts on its pages and headers (documented headers and the wording of its error pages); none is copied page content. A challenge or block rule always carries a vendor-specific marker next to the status.

Functions

This section is empty.

Types

type Marker

type Marker struct {
	// Header: the header is present (HeaderContains empty) or one of its
	// values contains HeaderContains.
	Header         string `json:"header,omitempty"`
	HeaderContains string `json:"header_contains,omitempty"`
	// HeaderPrefix: some header name starts with it.
	HeaderPrefix string `json:"header_prefix,omitempty"`
	// Cookie: a Set-Cookie sets a cookie whose name starts with it.
	Cookie string `json:"cookie,omitempty"`
	// Title: the page title contains it.
	Title string `json:"title,omitempty"`
	// Body: the first bytes of the body contain it.
	Body string `json:"body,omitempty"`
}

Marker is one condition on the answer; exactly one member is set. Values are compared lower-case.

type Rule

type Rule struct {
	ID         string   `json:"id"`
	Vendor     string   `json:"vendor"`
	State      State    `json:"state"`
	Status     []int    `json:"status,omitempty"`
	MaxBodyLen int      `json:"max_body_len,omitempty"`
	All        []Marker `json:"all"`
}

Rule fires when the status is one of Status (any status when empty), the body is at most MaxBodyLen bytes (when set) and every marker matches.

type State

type State string

State is what the edge did with a request.

const (
	// Direct: no edge marker in the answer.
	Direct State = "direct"
	// Fronted: an edge is in front and passed the request to the service.
	Fronted State = "fronted"
	// Challenged: the edge answered with an interactive or script challenge.
	Challenged State = "challenged"
	// Blocked: the edge refused the request (firewall rule, IP ban, bot
	// block).
	Blocked State = "blocked"
	// RateLimited: the edge throttled the request.
	RateLimited State = "rate_limited"
)

States, from "no edge seen" to "the edge refused".

func (State) Stops

func (s State) Stops() bool

Stops reports whether the edge stopped the request (challenge or block): the answer says nothing about the service behind it.

type Verdict

type Verdict struct {
	// Vendor is the edge vendor ("" when State is Direct).
	Vendor string `json:"vendor,omitempty"`
	State  State  `json:"state"`
	// Signal is the id of the rule that decided ("" when Direct).
	Signal string `json:"signal,omitempty"`
}

Verdict is the result of Classify.

func Classify

func Classify(status int, h http.Header, title string, body []byte) Verdict

Classify decides with DefaultRules.

func ClassifyWith

func ClassifyWith(rules []Rule, status int, h http.Header, title string, body []byte) Verdict

ClassifyWith decides with the given rules. status is the HTTP status, h the response headers (Set-Cookie included), title the page title when the caller already has one (otherwise it is read from the body) and body the first bytes of the body (a prefix is enough; more than MaxBody is ignored). A rule that fires on the strongest state wins; among equals, table order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL