helpers

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const SafeFetchClientMaxBodyBytes = 2 << 20

SafeFetchClientMaxBodyBytes caps response bodies for request-controlled fetches (OAuth client metadata / JWKS documents). 2 MiB is orders of magnitude beyond any legitimate OAuth metadata document while bounding memory use on hostile servers.

Variables

This section is empty.

Functions

func ExpiredTokenError

func ExpiredTokenError(e echo.Context) error

func ForbiddenError

func ForbiddenError(e echo.Context, suffix *string) error

func InputError

func InputError(e echo.Context, custom *string) error

func InsufficientScopeError added in v0.11.0

func InsufficientScopeError(e echo.Context, requiredScope string) error

InsufficientScopeError responds 403 per RFC 6750 §3.1 when the session's granted scopes do not cover the requested operation. requiredScope is the scope that would have permitted it (e.g. "repo:app.bsky.feed.post?action=create").

func InvalidTokenError

func InvalidTokenError(e echo.Context) error

func NewSafeFetchClient added in v0.11.2

func NewSafeFetchClient() *http.Client

NewSafeFetchClient returns the HTTP client used for fetches where the URL (or the host it resolves to) is influenced by an external party — notably OAuth client_id / jwks_uri lookups, whose targets are chosen by the registering client.

It uses gttp with strict SSRF protection: the IP policy (loopback, private, link-local, CGNAT, NAT64, IMDS ranges) applies to the initial request URL and to every redirect, validation is bound to the actual dial (a hostname resolving to a blocked address cannot be fetched), https->http downgrades are refused, and response bodies are size-capped.

Note for local development: strict SSRF protection intentionally blocks loopback targets. The OAuth "http://localhost" client_id is exempt because its metadata is built virtually and never fetched; a loopback-hosted client instance must be registered through a non-loopback origin.

func OauthNormalizeHtu

func OauthNormalizeHtu(u *url.URL) string

func OauthParseHtu

func OauthParseHtu(htu string) (string, error)

func ParseJWKFromBytes

func ParseJWKFromBytes(b []byte) (jwk.Key, error)

func RandomBytes

func RandomBytes(n int) []byte

func RandomHex

func RandomHex(n int) (string, error)

func RandomVarchar

func RandomVarchar(length int) string

func ServerError

func ServerError(e echo.Context, suffix *string) error

func UnauthorizedError

func UnauthorizedError(e echo.Context, suffix *string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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