Help us shape the future of Go! Take the 2026 Go Developer Survey

detect

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package detect recognises bot-challenge and WAF block pages.

Index

Constants

This section is empty.

Variables

View Source
var Signatures = []Signature{
	{
		Vendor:   "Cloudflare",
		Header:   func(h http.Header) bool { return strings.EqualFold(h.Get("cf-mitigated"), "challenge") },
		Body:     regexp.MustCompile(`(?i)(__cf_chl_|cf-browser-verification|cf_chl_opt|<title>Just a moment\.\.\.</title>|Attention Required! \| Cloudflare)`),
		Embedded: regexp.MustCompile(`(?i)/cdn-cgi/challenge-platform/`),
	},
	{

		Vendor: "Akamai",
		Body:   regexp.MustCompile(`(?i)(/_sec/verify\?provider=interstitial|triggerInterstitialChallenge|[?&]bm-verify=)`),
	},
	{
		Vendor:   "Akamai",
		Statuses: []int{403},

		Body: regexp.MustCompile(`(?is)Access Denied.*(Reference(\s|&#32;)*(#|&#35;)\d+(\.|&#46;)|errors(\.|&#46;)edgesuite(\.|&#46;)net)`),
	},
	{
		Vendor: "DataDome",
		Header: func(h http.Header) bool { return h.Get("X-DataDome") != "" && h.Get("X-DD-B") != "" },
		Body:   regexp.MustCompile(`(?i)(geo\.captcha-delivery\.com|ct\.captcha-delivery\.com|dd=\{'rt':'c')`),
	},
	{
		Vendor:   "PerimeterX",
		Statuses: []int{403, 429},
		Body:     regexp.MustCompile(`(?i)(/_px[a-z0-9]*/|px-captcha|_pxAppId|window\._pxUuid|Press &amp; Hold|Press & Hold)`),
	},
	{
		Vendor:   "Imperva",
		Body:     regexp.MustCompile(`(?i)(Incapsula incident ID|Request unsuccessful\. Incapsula)`),
		Embedded: regexp.MustCompile(`(?i)_Incapsula_Resource`),
	},
	{
		Vendor:   "Kasada",
		Header:   func(h http.Header) bool { return h.Get("X-Kpsdk-Ct") != "" || h.Get("X-Kpsdk-C") != "" },
		Embedded: regexp.MustCompile(`(?i)(/149e9513-01fa-4fb0-aad4-566afd725d1b/|KPSDK\.configure)`),
	},
	{
		Vendor: "AWS WAF",
		Header: func(h http.Header) bool {
			return strings.EqualFold(h.Get("X-Amzn-Waf-Action"), "challenge") || strings.EqualFold(h.Get("X-Amzn-Waf-Action"), "captcha")
		},
		Embedded: regexp.MustCompile(`(?i)(awswaf\.com/[^"']*challenge\.js|AwsWafIntegration)`),
	},
	{
		Vendor:   "Sucuri",
		Statuses: []int{403, 503},
		Body:     regexp.MustCompile(`(?i)(Sucuri WebSite Firewall|sucuri\.net/privacy-policy|cloudproxy@sucuri)`),
	},
	{
		Vendor: "CAPTCHA",

		Statuses: []int{401, 403, 405, 429, 503},
		Body:     regexp.MustCompile(`(?i)(class=["'][^"']*g-recaptcha|class=["'][^"']*h-captcha|class=["'][^"']*cf-turnstile|data-sitekey=)`),
	},
}

Signatures is checked in order; the first match wins.

Functions

func Challenge

func Challenge(status int, h http.Header, body []byte) string

Challenge returns the vendor whose challenge or block page this response is, or "" when none is recognised.

func Edge added in v1.1.0

func Edge(status int, h http.Header) string

Edge names the CDN or edge network that answered an error response, from its headers, so a blocked result can say who blocked it. It returns "" for successful responses or when no edge is recognised.

Types

type Signature

type Signature struct {
	Vendor string
	// Statuses restricts Body matching to these status codes. Empty means any.
	Statuses []int
	// Header reports whether response headers alone identify the vendor.
	Header func(h http.Header) bool
	// Body matches markers that only appear on the challenge or block page.
	Body *regexp.Regexp
	// Embedded matches scripts the vendor also injects into healthy pages
	// (Cloudflare's challenge platform, AWS WAF's challenge.js). They only
	// count when the response is not a success, or a healthy page that
	// happens to load the script would be reported as challenged.
	Embedded *regexp.Regexp
}

Signature describes how one vendor's challenge or block page looks.

A response matches when the vendor's header check passes, when Body (a marker only a challenge or block page contains) matches under the status filter, or when Embedded matches on a response that is not a success.

Jump to

Keyboard shortcuts

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