webpath

package
v1.5.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: 7 Imported by: 4 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 webpath is the one reading of a web request path shared by the platform and the sensor: how a server sees a path (CleanPath), whether a path falls under an excluded path (Denied) or an allowed prefix (Under), and whether a path names a state-changing action (Destructive).

The platform plans path discovery and filters candidate lists with these functions, and the sensor's web scope refuses requests with the same ones, so a candidate the platform keeps is never one the sensor would refuse for a different reason, and an exclusion can never be read two ways.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEncodedSeparator = errors.New("encoded separator in the path")
	ErrBadEscape        = errors.New("invalid percent-encoding in the path")
	ErrControl          = errors.New("control character in the path")
	ErrDotParams        = errors.New("dot segment with parameters in the path")
)

Errors of CleanPath.

View Source
var DestructiveVerbs = []string{
	"logout", "logoff", "signout", "delete", "remove", "destroy", "drop", "purge", "wipe",
	"reset", "shutdown", "restart", "reboot", "kill", "unsubscribe", "cancel", "revoke",
}

DestructiveVerbs are the words that mark a path as a state-changing action a GET may still trigger (a logout link, "/admin/delete?id=1"). Discovery never requests such a path and a crawler never follows one.

View Source
var ErrCandidate = errors.New("candidate path is not plain ASCII")

ErrCandidate is the error of CheckCandidate.

Functions

func CheckCandidate added in v1.3.1

func CheckCandidate(escaped string) error

CheckCandidate checks a guessed candidate path (escaped) before it is requested: CleanPath must accept it, and it may hold neither an escaped percent sign ("%25", read twice by some servers) nor a byte outside printable ASCII, raw or decoded (servers fold such letters to ASCII in different ways). A guess list never needs either.

func CleanDeny added in v1.3.1

func CleanDeny(d string) (string, error)

CleanDeny is the stored form of a deny path: percent-decoded and cleaned as CleanPath reads a request ("/files/My%20Docs" is "/files/My Docs"), so it compares with the path a server sees. A deny path CleanPath refuses is an error; a trailing slash is kept.

func CleanPath

func CleanPath(escaped string) (string, error)

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

func Denied

func Denied(p string, deny []string) (string, bool)

Denied returns the first deny path that a clean path falls under, in any reading. A deny path matches every path that starts with it, ignoring case: over-blocking is the safe side ("/admin" also denies "/Admin" and "/administrator"). A segment "*" of a deny path matches any one segment ("/tenants/*/admin" denies "/tenants/acme/admin/x"), as the platform's path exclusions read it.

Both sides are compared in the form a lenient server reads them: case folded to ASCII (a letter whose case folding includes an ASCII letter, such as U+017F for "s" or U+212A for "k", is that letter), and trailing dots and spaces of a segment dropped ("/admin./x" is "/admin/x" to a Windows server). A deny path is taken both as written and percent-decoded (an exclusion stored as "/files/My%20Docs" denies "/files/My Docs/a.bak"), so a deny list of either form holds.

func Destructive

func Destructive(p string) bool

Destructive reports whether a path (escaped or clean) names a state-changing action: a segment has a word that is one of DestructiveVerbs, or that starts with one ("deleteUser", "logout_all", "resetPassword"), or two adjacent words that join into one ("log-out", "sign_out"). Words are split on anything that is not a letter or a digit, and on a lower-to-upper case change. Over-blocking is the safe side.

func HasDotSegment

func HasDotSegment(p string) bool

HasDotSegment reports whether a path has a "." or ".." segment.

func Readings

func Readings(p string) []string

Readings are the paths a server may act on for a clean path: the path itself; when a segment has parameters (";jsessionid=..."), the path without them; and when the path still holds a percent-escape, the path a server that decodes twice sees ("/%2561dmin" reaches it as "/admin"). A check must pass for every reading.

func Under

func Under(p, prefix string) bool

Under reports whether a clean path is the prefix or under it, at a segment boundary, in every reading. An empty prefix or "/" is every path.

Types

This section is empty.

Jump to

Keyboard shortcuts

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