web

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 25 Imported by: 0 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 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

View Source
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.

View Source
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.

View Source
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.

View Source
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.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the listener's handler.

Jump to

Keyboard shortcuts

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