Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Prevent contact-email principal takeover

rcourtman53a928ee2df8
diff --git a/docs/release-control/v6/internal/IDENTITY_INVARIANTS.md b/docs/release-control/v6/internal/IDENTITY_INVARIANTS.md
index 38fb269402..7b683db868 100644
--- a/docs/release-control/v6/internal/IDENTITY_INVARIANTS.md
+++ b/docs/release-control/v6/internal/IDENTITY_INVARIANTS.md
@@ -76,7 +76,9 @@ principal once a stable user ID exists.
1. Handoff sessions bind to the signed stable subject or `UserID`, then verify
that subject against existing server-side organization membership. Blank or
email-shaped handoff subjects are invalid; email may only help find legacy
- email-keyed tenant records after a stable subject is already present.
+ email-keyed tenant records after a stable subject is already present. A
+ contact email attached to an already-stable owner/member principal must not
+ authorize or canonicalize a different stable subject.
2. Magic-link sessions bind to the stored organization principal resolved from
contact email at verification time, not to the email embedded in the token.
If the matching organization owner/member has no stored principal, the
diff --git a/docs/release-control/v6/internal/subsystems/organization-settings.md b/docs/release-control/v6/internal/subsystems/organization-settings.md
index 7c3588989e..acb8d64fb7 100644
--- a/docs/release-control/v6/internal/subsystems/organization-settings.md
+++ b/docs/release-control/v6/internal/subsystems/organization-settings.md
@@ -184,6 +184,10 @@ helper so handlers do not duplicate membership lookup or accidentally bind
sessions to email. A matching owner/member contact email without a stored
`OwnerUserID` or member `UserID` is not a principal; the helper must fail
closed instead of manufacturing a session key from email.
+Organization-principal canonicalization may use email only when the stored
+owner/member principal is itself legacy email-keyed. A contact email on an
+already-stable owner/member must not authorize, replace, or migrate a different
+stable subject.
That same org-control surface also treats owner transfer as a re-auth-bound
operation. Existing membership remains a prerequisite for the target user, and
the acting owner must present a fresh browser session minted through the
diff --git a/internal/api/identity_invariant_contract_test.go b/internal/api/identity_invariant_contract_test.go
index b95e48022c..590badcc68 100644
--- a/internal/api/identity_invariant_contract_test.go
+++ b/internal/api/identity_invariant_contract_test.go
@@ -137,6 +137,8 @@ func TestContract_HostedIdentityUsesStablePrincipals(t *testing.T) {
"OwnerEmail string",
"ResolvePrincipalByEmail",
"CanonicalizePrincipalIdentity",
+ "ownerMatchesLegacyEmailPrincipal",
+ "memberMatchesLegacyEmailPrincipal",
"return \"\", \"\", false",
},
"../../docs/release-control/v6/internal/IDENTITY_INVARIANTS.md": {
@@ -144,6 +146,7 @@ func TestContract_HostedIdentityUsesStablePrincipals(t *testing.T) {
"Pulse control-plane user ID",
"SSO provider subject",
"reject caller-supplied metadata",
+ "contact email attached to an already-stable owner/member principal must not",
"Self-hosted SSO sessions now use provider-scoped",
},
}
@@ -216,6 +219,8 @@ func TestContract_HostedIdentityUsesStablePrincipals(t *testing.T) {
},
"../models/organization.go": {
"userID = email",
+ "ownerMatchesUserID(o, userID) || ownerMatchesEmail(o, email)",
+ "memberMatchesUserID(member, userID) || memberMatchesEmail(member, email)",
},
}
for file, needles := range forbidden {
diff --git a/internal/models/organization.go b/internal/models/organization.go
index 1ae0ee7140..f1a677f51a 100644
--- a/internal/models/organization.go
+++ b/internal/models/organization.go
@@ -311,6 +311,25 @@ func ownerMatchesEmail(org *Organization, email string) bool {
return false
}
+func ownerMatchesLegacyEmailPrincipal(org *Organization, email string) bool {
+ if org == nil {
+ return false
+ }
+ ownerUserID := normalizeOrganizationIdentityValue(org.OwnerUserID)
+ if !identityLooksLikeEmail(ownerUserID) {
+ return false
+ }
+ return normalizeOrganizationEmail(ownerUserID) == normalizeOrganizationEmail(email)
+}
+
+func memberMatchesLegacyEmailPrincipal(member OrganizationMember, email string) bool {
+ userID := normalizeOrganizationIdentityValue(member.UserID)
+ if !identityLooksLikeEmail(userID) {
+ return false
+ }
+ return normalizeOrganizationEmail(userID) == normalizeOrganizationEmail(email)
+}
+
// HasMember checks if a user is a member of the organization.
func (o *Organization) HasMember(userID string) bool {
for _, member := range o.Members {
@@ -395,18 +414,18 @@ func (o *Organization) CanUserIDManage(userID string) bool {
}
// GetMemberRoleForPrincipal resolves a role using the durable user ID first,
-// then email only as a legacy/contact fallback.
+// then email only when the stored principal is still legacy email-keyed.
func (o *Organization) GetMemberRoleForPrincipal(userID, email string) OrganizationRole {
if o == nil {
return ""
}
- if ownerMatchesUserID(o, userID) || ownerMatchesEmail(o, email) {
+ if ownerMatchesUserID(o, userID) || ownerMatchesLegacyEmailPrincipal(o, email) {
return OrgRoleOwner
}
userID = normalizeOrganizationIdentityValue(userID)
email = normalizeOrganizationEmail(email)
for _, member := range o.Members {
- if memberMatchesUserID(member, userID) || memberMatchesEmail(member, email) {
+ if memberMatchesUserID(member, userID) || memberMatchesLegacyEmailPrincipal(member, email) {
return NormalizeOrganizationRole(member.Role)
}
}
@@ -457,7 +476,7 @@ func (o *Organization) CanonicalizePrincipalIdentity(userID, email string) bool
}
changed := false
- if ownerMatchesUserID(o, userID) || ownerMatchesEmail(o, email) {
+ if ownerMatchesUserID(o, userID) || ownerMatchesLegacyEmailPrincipal(o, email) {
if normalizeOrganizationIdentityValue(o.OwnerUserID) != userID {
o.OwnerUserID = userID
changed = true
@@ -470,7 +489,7 @@ func (o *Organization) CanonicalizePrincipalIdentity(userID, email string) bool
for i := range o.Members {
member := o.Members[i]
- if !memberMatchesUserID(member, userID) && !memberMatchesEmail(member, email) {
+ if !memberMatchesUserID(member, userID) && !memberMatchesLegacyEmailPrincipal(member, email) {
continue
}
oldUserID := normalizeOrganizationIdentityValue(member.UserID)
diff --git a/internal/models/organization_additional_test.go b/internal/models/organization_additional_test.go
index 21b77a1d32..fe02374fb9 100644
--- a/internal/models/organization_additional_test.go
+++ b/internal/models/organization_additional_test.go
@@ -62,6 +62,59 @@ func TestOrganizationPrincipalIdentityCanonicalization(t *testing.T) {
}
}
+func TestOrganizationPrincipalIdentityRejectsStableContactEmailCollision(t *testing.T) {
+ org := &Organization{
+ ID: "org-1",
+ OwnerUserID: "u_owner",
+ OwnerEmail: "[email protected]",
+ Members: []OrganizationMember{
+ {UserID: "u_owner", Email: "[email protected]", Role: OrgRoleOwner, AddedBy: "u_owner"},
+ {UserID: "u_admin", Email: "[email protected]", Role: OrgRoleAdmin, AddedBy: "u_owner"},
+ },
+ }
+
+ if role := org.GetMemberRoleForPrincipal("u_intruder", "[email protected]"); role != "" {
+ t.Fatalf("owner email collision role = %q, want empty", role)
+ }
+ if role := org.GetMemberRoleForPrincipal("u_intruder", "[email protected]"); role != "" {
+ t.Fatalf("member email collision role = %q, want empty", role)
+ }
+ if org.CanonicalizePrincipalIdentity("u_intruder", "[email protected]") {
+ t.Fatal("stable owner contact email must not canonicalize to a different principal")
+ }
+ if org.OwnerUserID != "u_owner" || org.Members[0].UserID != "u_owner" {
+ t.Fatalf("owner identity changed to (%q, %q), want stable owner unchanged", org.OwnerUserID, org.Members[0].UserID)
+ }
+ if org.CanonicalizePrincipalIdentity("u_intruder", "[email protected]") {
+ t.Fatal("stable member contact email must not canonicalize to a different principal")
+ }
+ if org.Members[1].UserID != "u_admin" {
+ t.Fatalf("admin identity changed to %q, want stable admin unchanged", org.Members[1].UserID)
+ }
+}
+
+func TestOrganizationPrincipalIdentityAllowsLegacyEmailKeyedMemberMigration(t *testing.T) {
+ org := &Organization{
+ ID: "org-1",
+ OwnerUserID: "u_owner",
+ OwnerEmail: "[email protected]",
+ Members: []OrganizationMember{
+ {UserID: "u_owner", Email: "[email protected]", Role: OrgRoleOwner, AddedBy: "u_owner"},
+ {UserID: "[email protected]", Role: OrgRoleAdmin, AddedBy: "[email protected]"},
+ },
+ }
+
+ if role := org.GetMemberRoleForPrincipal("u_admin", "[email protected]"); role != OrgRoleAdmin {
+ t.Fatalf("legacy member role = %q, want %q", role, OrgRoleAdmin)
+ }
+ if !org.CanonicalizePrincipalIdentity("u_admin", "[email protected]") {
+ t.Fatal("expected legacy member identity to canonicalize")
+ }
+ if org.Members[1].UserID != "u_admin" || org.Members[1].Email != "[email protected]" || org.Members[1].AddedBy != "[email protected]" {
+ t.Fatalf("member identity = (%q, %q, %q), want stable user with preserved contact metadata", org.Members[1].UserID, org.Members[1].Email, org.Members[1].AddedBy)
+ }
+}
+
func TestOrganizationStrictUserIDAccessRejectsContactEmail(t *testing.T) {
org := &Organization{
ID: "org-1",