Reject empty SAML NameIDs on login

Empty NameID values were stored as '' and occupied the
unique saml_subject index, causing duplicate-key failures
on later logins. Reject blank NameIDs during assertion
validation, return a clear error when a NameID is already
linked to another account, and stop returning internal
errors from the SAML consume endpoint.

Signed-off-by: Sacha Al Himdani <sacha@probo.com>
This commit is contained in:
Sacha Al Himdani
2026-07-24 09:47:09 +02:00
parent e12351e0f4
commit bcd05a2e55
5 changed files with 234 additions and 13 deletions

View File

@@ -104,3 +104,25 @@ func NewUserInactiveError(profileID gid.GID) error {
func (e ErrUserInactive) Error() string {
return fmt.Sprintf("user %q is inactive", e.ProfileID)
}
type ErrSAMLSubjectAlreadyInUse struct {
AssertionID string
}
func NewSAMLSubjectAlreadyInUseError(assertionID string) error {
return &ErrSAMLSubjectAlreadyInUse{AssertionID: assertionID}
}
func (e ErrSAMLSubjectAlreadyInUse) Error() string {
return fmt.Sprintf("SAML NameID is already linked to another account (assertion %q)", e.AssertionID)
}
type ErrSAMLSubjectRequired struct{}
func NewSAMLSubjectRequiredError() error {
return &ErrSAMLSubjectRequired{}
}
func (e ErrSAMLSubjectRequired) Error() string {
return "NameID value is required"
}