Documentation
¶
Overview ¶
Package web is the forge's web listener: OIDC sign-in through the identity bridge, server-side sessions, and the read-only repository pages.
Rules it keeps, each with a test:
- a sign-in never creates an account, never links an identity to a session that already exists, and never looks at an e-mail address: the only key is (issuer, subject), read through store.LoginForIdentity;
- every refusal of a sign-in is the same page, so the reason is no oracle;
- the session cookie is __Host-, Secure, HttpOnly and SameSite=Lax, its value is random and only its SHA-256 is stored, it is replaced at every sign-in, and it dies by idle time, by age, and with the account or the binding;
- a state-changing request (logout) is a POST carrying the session's token;
- every response carries a CSP with no inline script and no inline style.
Index ¶
Constants ¶
const ( SessionCookie = "__Host-forge_session" FlowCookie = "__Host-forge_flow" )
Cookie names. The __Host- prefix makes a browser accept the cookie only with Secure, Path=/ and no Domain (RFC 6265bis §4.1.3.2), so a sibling host cannot plant one.
const ( DefaultIdle = 30 * time.Minute DefaultAbs = 12 * time.Hour DefaultFlowTTL = 10 * time.Minute // MaxFlows bounds the sign-ins in progress. A flood evicts the oldest. MaxFlows = 1024 // MaxCode and MaxNext bound what the callback and /login accept. MaxCode = 2048 MaxNext = 512 // MaxForm bounds a POST body. MaxForm = 4 << 10 )
Defaults.
const CSP = "default-src 'none'; style-src 'self'; img-src 'self'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'"
CSP is the policy of every response: nothing but our own stylesheet, no script at all (inline or not), no framing, no base tag, forms only to us.
const CallbackPath = "/callback"
CallbackPath is where the identity bridge returns the browser. The redirect URI registered with `forgectl oidc set-client` must end with it.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
Store *store.Store
// Seal opens the stored client secret; nil serves public clients only.
Seal *secretbox.Box
// HTTP reaches the bridge (nil: a client that refuses redirects to cleartext
// and times out).
HTTP *http.Client
Log *slog.Logger
// Now is the clock (nil: time.Now).
Now func() time.Time
// Zero fields mean the defaults.
Idle, Abs, FlowTTL time.Duration
// Repos serves the repository pages (nil: there are none).
Repos *gitrepo.Service
// Limiter caps the repository pages at once, in total and per reader
// (nil: no cap).
Limiter *gitrepo.Limiter
// GitTimeout bounds one git command of a page (0: gitview.DefaultTimeout).
GitTimeout time.Duration
// contains filtered or unexported fields
}
Server is the web listener's handler.