identity

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 8 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 identity is the shared definition of how a scan's requests identify themselves to a target: the User-Agent values a layer may set, and how one value of a rotation list is chosen for a target host.

The platform validates every layer (platform, organization, program) with these functions and the sensor validates the job it receives with the same ones, so a value one side accepts is one the other side sends. The selection is defined once here so the platform can show which User-Agent a host gets in a run and the sensor sends exactly that one.

User-Agent rotation

A layer may give a list of up to MaxUserAgents values instead of one. SelectUserAgent picks one value per (key, host): the key is the scan run (the platform puts the run's id in the job), the host is the target host a request goes to. The choice is sticky: every request of one run to one host carries the same value, so a session never changes its fingerprint half way. Different runs and different hosts spread evenly over the list (HMAC-SHA-256 keyed by the run key, over the canonical host).

Rotation never replaces the identification of a scan: identification headers and the identification query parameter are sent with every value of the list, and a job that requires identification is refused where a tool cannot carry it (see the sensor SDK's tool host).

Index

Constants

View Source
const (
	// MaxUserAgents is the most values a rotation list may hold.
	MaxUserAgents = 200
	// MaxUserAgentLen is the longest value, in bytes.
	MaxUserAgentLen = 256
	// MaxKeyLen is the longest selection key, in bytes.
	MaxKeyLen = 128
)

Bounds of the User-Agent values.

Variables

View Source
var ErrInvalid = errors.New("invalid identification")

ErrInvalid is wrapped by every validation error of this package.

Functions

func CanonicalHost

func CanonicalHost(target string) string

CanonicalHost is the host a selection is made for: the host of a URL, a host:port or a bare host, lower-cased, without a port, IPv6 brackets or a trailing dot. "https://WWW.Example.com.:8443/a" and "www.example.com" give the same host, so every port and scheme of a host gets one value.

func CheckKey

func CheckKey(key string) error

CheckKey accepts a selection key of at most MaxKeyLen printable ASCII characters ("" is valid: the selection then depends on the host alone).

func CheckUserAgent

func CheckUserAgent(ua string) error

CheckUserAgent accepts a User-Agent of 1 to MaxUserAgentLen printable ASCII characters with no leading or trailing space.

func CheckUserAgents

func CheckUserAgents(list []string) error

CheckUserAgents accepts a rotation list: at most MaxUserAgents values, each valid (CheckUserAgent), none twice. An empty list is valid (no rotation).

func SelectIndex

func SelectIndex(key, host string, n int) int

SelectIndex returns the index in a list of n values that (key, host) gets: HMAC-SHA-256 keyed by key over the label and the canonical host, read as a big-endian uint64, modulo n. The bias of the modulo is below n/2^64. -1 when n < 1.

func SelectUserAgent

func SelectUserAgent(key, host string, list []string) string

SelectUserAgent returns the value of list that (key, host) gets (SelectIndex); "" for an empty list.

Types

This section is empty.

Jump to

Keyboard shortcuts

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