sessionbinding

package
v0.51.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sessionbinding binds sessions to the validated issuer and subject, never to a bearer token. Authentication must run before ownership enforcement.

Index

Constants

MetadataKey is shared with persisted vMCP sessions for compatibility.

View Source
const UnauthenticatedSentinel = "unauthenticated"

UnauthenticatedSentinel is reserved for an actually absent identity.

Variables

View Source
var (
	// ErrInvalidBinding denotes malformed issuer/subject claims.
	ErrInvalidBinding = errors.New("invalid identity binding")
	// ErrNotFound deliberately conceals missing, unowned and foreign sessions.
	ErrNotFound = session.ErrSessionNotFound
)

Functions

func AddOwnedSession

func AddOwnedSession(ctx context.Context, manager Store, sess session.Session) error

AddOwnedSession binds an ordinary proxy session before atomic publication. sess must be newly constructed and unpublished; its metadata is modified. A collision may reuse only the same owner's record, never replace metadata. Shared storage does not provide cross-replica live-stream delivery.

func BindOwner

func BindOwner(ctx context.Context, sess session.Session) error

BindOwner sets ownership before insertion, never on a published session.

func Check

func Check(r *http.Request, id string, lookup Lookup) error

Check validates a session-bearing request using its authenticated context. Empty IDs are sessionless; callers enforce any protocol-required ID separately.

func Format

func Format(iss, sub string) (string, error)

Format encodes a nonempty issuer and subject separated by exactly one NUL.

func FromIdentity

func FromIdentity(identity *auth.Identity) (string, error)

FromIdentity accepts nil only for auth-disabled deployments. A synthetic anonymous/local identity with valid claims binds normally; malformed non-nil identities must never downgrade to the unauthenticated sentinel.

func NewMiddleware

func NewMiddleware(extract func(*http.Request) (string, error), lookup Lookup,
	reject func(http.ResponseWriter, *http.Request, error)) (func(http.Handler) http.Handler, error)

NewMiddleware constructs ownership enforcement. extract must classify requests without consuming their bodies and return an empty ID only for truly sessionless requests. reject must conceal ErrNotFound (404) and map storage failures to 503. Install inside authentication and outside stateful handlers/restoration.

func Parse

func Parse(value string) (iss, sub string, ok bool)

Parse rejects malformed bindings and the unauthenticated sentinel.

func RequestID

func RequestID(r *http.Request, queryKey string) (string, error)

RequestID reads protocol session carriers, rejecting duplicate or conflicting values before a backend can interpret them differently. queryKey may be empty.

func Validate

func Validate(stored string, identity *auth.Identity) error

Validate fails closed for legacy records without an owner. Refreshed tokens for the same issuer and subject are accepted. It never mutates session state.

func WriteOwnershipError

func WriteOwnershipError(w http.ResponseWriter, requestID any, err error)

WriteOwnershipError uses the ordinary proxies' non-disclosing JSON-RPC 404.

Types

type Lookup

type Lookup func(context.Context, string) (string, error)

Lookup reads authoritative owner metadata only, without restoring SDK sessions or connecting to backends. Return ErrNotFound for absent records, and propagate storage errors. Shared storage does not provide live-stream affinity.

type Store

type Store interface {
	AddSession(session.Session) error
	LookupOwner(context.Context, string) (string, error)
}

Store is the ordinary session manager surface required for conditional publication.

Jump to

Keyboard shortcuts

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