webdiff

package
v0.51.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 25 Imported by: ? modules, 0 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 webdiff is the calibrated differ of path and parameter discovery: it tells a response that shows something exists apart from the many ways a web server answers "nothing here" (a 404, a soft-404 page that answers 200, a single-page app that serves its index for every path, a wildcard API subtree, a login wall, a firewall rule that blocks a keyword).

A Prober works on one origin (scheme://host[:port]) for one task. For each class of candidate (its directory and its shape: bare, slash, a file extension, a dot file) it first requests three random names, keeps their signatures (Sig: status, redirect pattern, content-type family, length, words, lines, title, header names, simhash of the normalised body) and derives a noise band. A candidate is a hit only when its answer differs from that baseline beyond the band, the difference repeats, and, for a directory or a 403, a random child of it answers like a missing path.

Safety:

  • every request is a GET of a path of the origin; redirects are never followed (the Location is only read as a pattern), so a redirect to an internal address or another host is never requested;
  • a body is read up to MaxBody bytes; a gzip body is decoded by the prober with the expansion ratio bounded; headers are bounded; the whole exchange has a deadline and the body a minimum transfer rate. An answer that breaks a bound stops the origin (hostile_response);
  • an edge challenge or block (contract edgeprotect) is never a signal and stops the origin (edge_protected); 429 and 503 back off and are retried at most Retries times, never a hit;
  • baselines live in the Prober, which lives for one task: nothing is cached across tasks, so one task's probes never shape another's;
  • nothing of a body leaves the package but its size and a 64-bit hash of its normalised text.

The client is used as given apart from its redirect policy: on a sensor it is the task's tool.Context.HTTP client, so the job's web scope, its request cap, the address pinning and the pacing of the task forwarder apply to every request.

Stability: Experimental (docs/STABILITY.md).

Index

Constants

View Source
const (
	// ShapeBare: "/dir/x".
	ShapeBare = "bare"
	// ShapeSlash: "/dir/x/".
	ShapeSlash = "slash"
	// ShapeDot: "/dir/.x".
	ShapeDot = "dot"
)

Shapes of a candidate's last segment.

View Source
const (
	ResponseKey = "response"
	LabelsKey   = "labels"
)

ResponseKey is the member of an endpoint's io.openctem extension that carries a hit's evidence: {"size": <decoded body bytes read>, "hash": "<16 hex>"}. LabelsKey carries its labels.

View Source
const (
	// GapCatchAll: the origin answers every path with its index page; bare
	// and directory candidates were skipped (file shapes still ran).
	GapCatchAll = "catch_all"
	// GapAuthWall: the origin redirects every path to a login page or
	// answers 401; an authenticated run would see more.
	GapAuthWall = "auth_wall"
	// GapEdgeProtected: an edge protection (WAF, CDN) challenged or
	// blocked the requests; the origin was stopped.
	GapEdgeProtected = "edge_protected"
	// GapThrottled: the origin kept answering 429 or 503; the origin was
	// stopped.
	GapThrottled = "throttled"
	// GapBlocked: the origin stopped answering (resets, timeouts); the
	// origin was stopped.
	GapBlocked = "blocked"
	// GapUnstableBaseline: a class's random names did not answer alike;
	// its candidates were skipped.
	GapUnstableBaseline = "unstable_baseline"
	// GapBudget: the request budget ran out before the candidates did.
	GapBudget = "budget"
	// GapHostileResponse: an answer broke a bound (decompression bomb,
	// huge headers, a body slower than the minimum rate or the deadline);
	// the origin was stopped.
	GapHostileResponse = "hostile_response"
	// GapProtocol: the origin does not speak HTTP/1.1; the origin was
	// stopped.
	GapProtocol = "protocol"
	// GapScopeFiltered: candidates the job's web scope refused (or that
	// name a state-changing action) and that were never requested.
	GapScopeFiltered = "scope_filtered"
)

Gap reasons: why an origin, or some of its candidates, was not covered.

View Source
const (
	AuthNone          = "none"
	AuthRequired      = "required"
	AuthRedirectLogin = "redirect_login"
)

Auth states of a hit.

View Source
const (
	LabelDirectory        = "directory"
	LabelForbidden        = "status:forbidden"
	LabelError            = "status:error"
	LabelRedirect         = "status:redirect"
	LabelMethodNotAllowed = "status:method_not_allowed"
)

Labels of a hit.

View Source
const (
	DefaultMaxBody        = 256 << 10
	DefaultMaxHeaderBytes = 64 << 10
	DefaultDeadline       = 10 * time.Second
	DefaultMinRate        = 512
	DefaultMinRateAfter   = 2 * time.Second
	DefaultMaxRatio       = 100
	DefaultRetries        = 2
	DefaultRate           = 5
	// MaxRate bounds Options.Rate: a config value above it is lowered to it.
	MaxRate = 50
	// FrontedRate is the rate of an origin an edge network fronts (the first
	// answer that carries an edge marker lowers the limiter to it).
	FrontedRate        = 2
	DefaultRecalibrate = 200
	DefaultMinBackoff  = time.Second
	DefaultMaxBackoff  = 30 * time.Second
)

Defaults of Options.

Variables

View Source
var ErrStopped = errors.New("webdiff: the origin is stopped")

ErrStopped is returned for every candidate once the origin is stopped; Prober.Stopped names the reason.

Functions

func Distance

func Distance(a, b uint64) int

Distance is the Hamming distance of two simhashes.

func Endpoint

func Endpoint(origin string, h *Hit) ctis.Endpoint

Endpoint is the CTIS endpoint of a confirmed hit on origin: method GET, the concrete path, status, media type, auth state, source probe (the platform sets the source from the capability that ran), and the evidence (size and hash of the normalised body) and labels in the io.openctem extension. It carries no body, title or header value.

func Family

func Family(contentType string) string

Family is the content-type family of a Content-Type value.

func LocationPattern

func LocationPattern(reqURL *url.URL, location string, tokens ...string) string

LocationPattern is the pattern of a redirect target: resolved against the request URL, the host dropped when it is the request's (lower-cased otherwise), the fragment dropped, and every form of each token replaced by {r}.

func Normalize

func Normalize(body string, tokens ...string) string

Normalize removes what changes from one answer to the next from a body: every form of token (raw, URL-encoded, HTML-escaped, case-insensitive), then UUIDs, nonce attributes, hidden input fields, hex runs of 16 or more, base64 runs of 24 or more and digit runs. Two answers of the same page normalise to the same text.

func ShapeOf

func ShapeOf(name string) string

ShapeOf is the shape of a last segment: slash when it ends in "/", dot when it starts with ".", ext:<e> when it has an extension of letters and digits (lower-cased), else bare.

func SimHash

func SimHash(s string) uint64

SimHash is a 64-bit simhash over the word 3-shingles of s (single words when s has fewer than three). Similar texts have hashes a few bits apart.

func Split

func Split(p string) (dir, name, shape string)

Split splits a candidate path into its directory (ending in "/"), its last segment (with its trailing slash, if any) and its shape.

Types

type Hit

type Hit struct {
	// Path is the path as requested (escaped).
	Path string
	// Status, ContentType, Size and Hash are the evidence of the answer:
	// its status, media type, decoded body bytes read and the 64-bit hash
	// of its normalised body (16 hex).
	Status      int
	ContentType string
	Size        int
	Hash        string
	// Auth is none, required or redirect_login.
	Auth string
	// Labels are LabelDirectory and the status labels.
	Labels []string
}

Hit is a confirmed path: what discovery reports. It carries no body, title or header value.

type Options

type Options struct {
	// MaxRequests is the most requests the prober sends to the origin,
	// calibration and confirmation included (0: no cap of its own; the
	// job's web scope still caps the task).
	MaxRequests int
	// Rate is the most requests per second (default 5, at most MaxRate; an
	// origin an edge network fronts is held to FrontedRate).
	Rate float64
	// MaxBody is the most decoded body bytes read per answer (256 KiB).
	MaxBody int
	// MaxHeaderBytes bounds an answer's headers (64 KiB). The client's
	// transport should bound them too (http.Transport
	// MaxResponseHeaderBytes): this check runs after they were read.
	MaxHeaderBytes int
	// Deadline bounds one whole exchange, headers and body (10 s).
	Deadline time.Duration
	// MinRate is the slowest body, in bytes per second, accepted once
	// MinRateAfter has passed (512 B/s after 2 s).
	MinRate      int
	MinRateAfter time.Duration
	// MaxRatio is the largest expansion of a gzip body (100:1).
	MaxRatio int
	// Retries is how many times a 429, a 503 or a network error is
	// retried (2).
	Retries int
	// MinBackoff and MaxBackoff bound the wait before a retry (1 s, 30 s;
	// a Retry-After within them is used).
	MinBackoff, MaxBackoff time.Duration
	// RecalibrateAfter is how many requests a baseline serves before it is
	// taken again (200).
	RecalibrateAfter int
	// Rand is the source of the random names (crypto/rand).
	Rand io.Reader
}

Options bound a Prober. Zero values take the defaults.

type Prober

type Prober struct {
	// contains filtered or unexported fields
}

Prober probes the candidates of one origin for one task. It is not safe for concurrent use.

func New

func New(client *http.Client, origin string, o Options) (*Prober, error)

New returns the prober of origin ("https://app.example.com[:port]"; a path, query or credentials in it are refused). client is copied with redirects off.

func (*Prober) AddGap

func (p *Prober) AddGap(reason string, n int)

AddGap records a gap reason the caller met (n candidates; for example GapScopeFiltered for candidates it never handed over).

func (*Prober) Canary

func (p *Prober) Canary(ctx context.Context) (edgeprotect.Verdict, error)

Canary opens an origin: GET / (an edge challenge or block there stops the origin, edge_protected, and is returned before anything else is sent), then the root's bare baseline. A login redirect or a 401 records auth_wall; a random path that answers like / makes the origin catch-all (its bare and directory candidates are skipped, file shapes still run).

func (*Prober) CaseInsensitive

func (p *Prober) CaseInsensitive(ctx context.Context, h *Hit) (bool, error)

CaseInsensitive reports whether the origin ignores the case of a path: the hit's path with the case of its letters flipped answers like the hit and unlike the baseline. A caller then de-duplicates its remaining candidates ignoring case. One request (plus a calibration when needed).

func (*Prober) Check

func (p *Prober) Check(ctx context.Context, cand string) (Result, error)

Check probes one candidate path (escaped, starting with "/", no query): it calibrates the candidate's class when needed, requests the path, compares the answer, and confirms a difference before it reports a hit. It returns ErrStopped once the origin is stopped.

func (*Prober) FoldsCase

func (p *Prober) FoldsCase() bool

FoldsCase reports whether the origin was found to ignore the case of a path (CaseInsensitive).

func (*Prober) Gaps

func (p *Prober) Gaps() map[string]int

Gaps are the gap reasons met so far, each with the number of candidates it concerned (1 for an origin-wide reason).

func (*Prober) Origin

func (p *Prober) Origin() string

Origin is the origin probed.

func (*Prober) Requests

func (p *Prober) Requests() int

Requests is how many requests the prober sent.

func (*Prober) Stopped

func (p *Prober) Stopped() string

Stopped is why the origin was stopped ("" while it runs): one of the gap reasons.

type Result

type Result struct {
	Verdict Verdict
	// Hit is the confirmed hit (nil when the candidate is not one).
	Hit *Hit
	// Skipped is the gap reason when the candidate was not requested
	// (catch_all, unstable_baseline, scope_filtered).
	Skipped string
}

Result is the outcome of one candidate.

type Sig

type Sig struct {
	// Status is the HTTP status as received.
	Status int
	// Location is the redirect target as a pattern: the probed name
	// replaced by {r}, the host lower-cased and dropped when it is the
	// origin's ("" without a Location).
	Location string
	// Family is the content-type family: html, json, xml, js, text, binary
	// or none (no Content-Type).
	Family string
	// ContentType is the media type (no parameters), at most 128 bytes.
	ContentType string
	// Length, Words and Lines are measured over the normalised body.
	Length, Words, Lines int
	// Title is the page title, normalised, at most 256 bytes.
	Title string
	// Headers is a hash of the response's header names, volatile ones
	// (Date, Set-Cookie, request ids, ...) excluded.
	Headers uint64
	// SimHash is a 64-bit simhash over word 3-shingles of the normalised
	// body.
	SimHash uint64
	// Size is the number of decoded body bytes read (at most MaxBody).
	Size int
	// Hash is the first 64 bits of the SHA-256 of the normalised body, 16
	// lower-case hex characters.
	Hash string
	// Truncated is set when the body was longer than what was read.
	Truncated bool
}

Sig is what the differ keeps of one response: its signature. Nothing of the body leaves it but a length, a hash and counts.

type Verdict

type Verdict string

Verdict is the reading of a candidate's answer against its class's baseline.

const (
	Same      Verdict = "same"
	Different Verdict = "different"
	// NoSignal: the answer says nothing about the path (an edge page, a
	// rate limit, a network error, a refusal by the sensor).
	NoSignal Verdict = "no_signal"
)

Verdicts.

Jump to

Keyboard shortcuts

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