feat(identity): enforce shared session and browser request security
This commit is contained in:
1 parent
7df521bd89
commit
86f562f5b6
23 files changed
+430
-121
No files matched your search
@@ -23,11 +23,10 @@ type IdentityHandlerOption func(*IdentityHandler)
|
||||
|
||||
// IdentityHandler serves authentication and account identity operations.
|
||||
type IdentityHandler struct {
|
||||
registration AccountRegistration
|
||||
confirmation EmailConfirmation
|
||||
confirmationOrigin string
|
||||
sessions *identity.SessionService
|
||||
sessionOrigin string
|
||||
registration AccountRegistration
|
||||
confirmation EmailConfirmation
|
||||
sessions *identity.SessionService
|
||||
publicOrigin string
|
||||
}
|
||||
|
||||
func NewIdentityHandler(registration AccountRegistration, options ...IdentityHandlerOption) *IdentityHandler {
|
||||
@@ -38,21 +37,26 @@ func NewIdentityHandler(registration AccountRegistration, options ...IdentityHan
|
||||
return handler
|
||||
}
|
||||
|
||||
// WithEmailConfirmation serves ConfirmEmail and compares Origin with the
|
||||
// configured public application origin. The request Host is never trusted.
|
||||
func WithEmailConfirmation(confirmation EmailConfirmation, publicOrigin string) IdentityHandlerOption {
|
||||
// WithEmailConfirmation serves ConfirmEmail. The configured public origin is
|
||||
// supplied once with WithPublicOrigin; the request Host is never trusted.
|
||||
func WithEmailConfirmation(confirmation EmailConfirmation) IdentityHandlerOption {
|
||||
return func(handler *IdentityHandler) {
|
||||
handler.confirmation = confirmation
|
||||
handler.confirmationOrigin = publicOrigin
|
||||
}
|
||||
}
|
||||
|
||||
// WithSessionService serves login, current account, current session, and
|
||||
// logout against PostgreSQL-backed sessions. Unsafe browser operations compare
|
||||
// Origin exactly with the configured public origin.
|
||||
func WithSessionService(sessions *identity.SessionService, publicOrigin string) IdentityHandlerOption {
|
||||
// logout against PostgreSQL-backed sessions.
|
||||
func WithSessionService(sessions *identity.SessionService) IdentityHandlerOption {
|
||||
return func(handler *IdentityHandler) {
|
||||
handler.sessions = sessions
|
||||
handler.sessionOrigin = publicOrigin
|
||||
}
|
||||
}
|
||||
|
||||
// WithPublicOrigin configures the exact browser Origin accepted by unsafe
|
||||
// public identity operations and session CSRF checks.
|
||||
func WithPublicOrigin(publicOrigin string) IdentityHandlerOption {
|
||||
return func(handler *IdentityHandler) {
|
||||
handler.publicOrigin = publicOrigin
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user