webscope

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: 6 Imported by: 1 module, 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 webscope is the web scope of a job: which hosts, paths and methods a web tool (a crawler, a DAST scanner) may request. The platform puts it in the job; the SDK refuses every request outside it, whatever the tool does (tool.Context.HTTP), and the sensor maps it onto the flags of a tool that makes its own requests.

A job without a web scope is unrestricted by this package (the target hosts and the egress guard still apply).

Stability: Beta (docs/STABILITY.md).

Index

Constants

View Source
const (

	// MaxRequestsPerHostLimit is the largest MaxRequestsPerHost a scope
	// may carry.
	MaxRequestsPerHostLimit = 1_000_000
)

Bounds of a web scope.

Variables

View Source
var ErrOutOfScope = errors.New("outside the job's web scope")

ErrOutOfScope is the error of a request outside the web scope.

Functions

func CleanPath

func CleanPath(u *url.URL) (string, error)

CleanPath is the path a server sees for u: percent-decoded, dot segments resolved, never empty. A path with an encoded slash, backslash or NUL, a control character, or a dot segment with parameters ("..;") is refused: servers disagree on it (webpath.CleanPath).

func HostMatches

func HostMatches(pattern, host string) bool

HostMatches reports whether host matches the pattern: equal ignoring case and a trailing dot, or, for "*.example.com", example.com and any name under it.

Types

type Scope

type Scope struct {
	// Hosts are the hosts a request may go to: a host name or address
	// ("app.example.com"), or "*.example.com" for the domain and every
	// name under it. Empty: the job's target hosts.
	Hosts []string `json:"hosts,omitempty"`
	// PathPrefixes are the paths a request may go to ("/app", "/api/v2/").
	// A prefix matches itself and the paths under it, at a segment
	// boundary. Empty: every path.
	PathPrefixes []string `json:"path_prefixes,omitempty"`
	// DenyPaths are paths a request never goes to ("/logout", "/admin"),
	// whatever PathPrefixes allows. A deny path matches every path that
	// starts with it, ignoring case: over-blocking is the safe side. A
	// segment "*" matches any one segment ("/tenants/*/admin"). A deny path
	// holds as written and percent-decoded (webpath.Denied).
	DenyPaths []string `json:"deny_paths,omitempty"`
	// Methods are the HTTP methods a request may use. Empty: GET, HEAD
	// and OPTIONS.
	Methods []string `json:"methods,omitempty"`
	// MaxRequestsPerHost is the most HTTP requests the task may send to
	// one host name, whatever the port, connection or scheme (0: no cap).
	// The task's forwarder counts every request it lets through and
	// refuses the ones past the cap, as it refuses a request outside the
	// scope; the task cannot reset the count.
	MaxRequestsPerHost int `json:"max_requests_per_host,omitempty"`
}

Scope is a job's web scope.

func (*Scope) Allows

func (s *Scope) Allows(method string, u *url.URL, targets []string) error

Allows reports whether a request may go to u with method; the error names why not. targets are the job's target hosts, the hosts of a scope that names none.

func (*Scope) Validate

func (s *Scope) Validate() error

Validate checks the scope's bounds and syntax, and adds the clean form of every deny path that is written another way ("/files/My%20Docs" also denies as "/files/My Docs"), so a deny list from a platform that stored escaped paths holds on a tool that reads the list itself. A job whose scope is invalid is refused, never run unrestricted.

Jump to

Keyboard shortcuts

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