header

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IdempotencyKeyHeader     = "Idempotency-Key"
	IdempotentReplayedHeader = "Idempotent-Replayed"
	ContentTypeHeader        = "Content-Type"
	VersionHeader            = "OpenMRP-Version"
	TargetAccountIDHeader    = "OpenMRP-Account"
	ActorAccountIDHeader     = "OpenMRP-Actor-Account"
	AuthorizationHeader      = "Authorization"
	RequestIDHeader          = "Request-ID"
	WwwAuthenticateHeader    = "WWW-Authenticate"
	RetryAfterHeader         = "Retry-After"
	RateLimitLimitHeader     = "RateLimit-Limit"
	RateLimitRemainingHeader = "RateLimit-Remaining"
	RateLimitResetHeader     = "RateLimit-Reset"
	LocationHeader           = "Location"

	// InternalIdentityHeader carries a JSON-serialized agent identity on the internal listener. It is trusted ONLY when InternalServiceTokenHeader matches the configured secret. The edge/ingress must strip any X-OpenMRP-Internal-* headers from external traffic.
	InternalIdentityHeader = "X-OpenMRP-Internal-Identity"
	// InternalServiceTokenHeader carries the shared service token that gates the internal listener's identity trust.
	InternalServiceTokenHeader = "X-OpenMRP-Service-Token" // #nosec G101 -- header name, not a credential
)

Variables

View Source
var (
	ErrHeaderPrefix = "Invalid Authorization header format."
	// #nosec G101 - This is an error message, not a hardcoded credential
	ErrAPIKeyInvalid    = "Invalid API Key provided."
	ErrEnvMisconfigured = "You might have forgotten to setup your API key in your environment."
)

Functions

func GetClientIP

func GetClientIP(r *http.Request, trustedProxyHops int) net.IP

GetClientIP returns the client IP address for the request, using the X-Forwarded-For chain only to the extent it can be trusted.

trustedProxyHops is the number of reverse-proxy hops in front of this service. Each trusted proxy is expected to APPEND the IP of the connection it received from to X-Forwarded-For (this is what AWS ALB does). The rightmost trustedProxyHops entries in the chain are therefore the ones written by trusted infrastructure, and the entry at position `len(parts) - trustedProxyHops` is the IP of the original client as observed by the outermost trusted proxy.

When trustedProxyHops is 0 (no trusted proxy in front), the X-Forwarded-For header is ignored entirely — it is fully attacker-controlled and must not be used for any security-sensitive purpose such as rate limiting. RemoteAddr is returned instead.

When fewer XFF entries are present than expected, the trusted-proxy chain was not fully traversed, and we fall back to RemoteAddr rather than risk trusting an attacker-supplied entry.

func IsAPIKey

func IsAPIKey(token string) bool

Types

type AuthHeaderResult

type AuthHeaderResult struct {
	TokenString string
	Scheme      AuthScheme
}

func ValidateAndExtractAuthHeader

func ValidateAndExtractAuthHeader(authHeader string) (*AuthHeaderResult, *apierror.APIError)

type AuthScheme

type AuthScheme string
const (
	AuthSchemeBasic  AuthScheme = "basic"
	AuthSchemeBearer AuthScheme = "bearer"
)

Jump to

Keyboard shortcuts

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