feat(auth): OAuth2 role-based mailbox access for OAUTHBEARER - #283
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces role-based mailbox access for OAUTHBEARER authentication by extracting roles from JWT claims and evaluating access for role-based SASL identities. Feedback highlights critical security concerns, including a lack of domain validation in EvaluateRoleAccess that could lead to unauthorized cross-domain access and a potential path traversal vulnerability due to unsanitized input in mailbox identity construction. Additionally, a minor code improvement was suggested to remove redundant whitespace trimming.
Aravinda-HWK
deleted the
273-feature-oauth2-authentication-support-for-role-based-email-access
branch
May 17, 2026 13:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Description
Adds OAuth2 role-based mailbox access to the OAUTHBEARER SASL flow. A token holder can authenticate to a shared role mailbox (e.g.
support@example.com) when the validated JWT contains a matching entry in itsroles(orrole) claim. Personal mailbox authentication is unchanged.🔍 Changes Made
roles(array or string) and singularroleclaims inextractClaims(internal/auth/oauthbearer/oauthbearer.go).EvaluateRoleAccesshelper that returns aRoleAccessRequest(role, domain, mailbox identityrole_<role>@<domain>.db) when the SASLuser=<email>is a role address and the role appears in the token's roles. Case-insensitive; trims trailing dots from the domain.internal/sasl/server.go) — falls back to role access when the SASL user does not match the resolved token email.AUTHENTICATEhandler (internal/server/auth/auth.go) so the resolved mailbox identity is used forExtractUsernameandEnsureUserAndMailboxes, and stored on session state.role/ missing) andEvaluateRoleAccess(match, case-insensitive, non-role address, missing@, empty roles, trailing-dot domain).✅ Checklist (Email System)
LOGIN,CAPABILITY,LIST,SELECT,FETCH,LOGOUT).🧪 Testing Instructions
Unit tests:
Manual / IMAP:
rolesclaim containssupport(or singular"role": "support").AUTHENTICATE OAUTHBEARERwithuser=support@<your-domain>and the token above.role_support@<your-domain>.db— look forOAUTHBEARER: role-based access granted ...in the logs.alice@<your-domain>) — behaviour must be unchanged.user=support@<your-domain>with a token whose roles do not includesupportmust fail withAuthentication failed.Broader IMAP setup: see the test README.
📷 Screenshots / Logs (if applicable)
N/A — relevant log lines emitted by the new branches:
OAUTHBEARER: role-based access granted token_user=... role=... mailbox=...SASL OAUTHBEARER: role-based access granted ...role_<role>@<domain>.dbis chosen to align with the role-mailbox naming used by the socketmap path in 271 feature support role based email validation in socketmap user exist check #272 — please flag if a different convention is preferred.EvaluateRoleAccessreturnsnilfor anything that is not exactlyrole@domain, so personal-mailbox auth always falls through to the existing equality check (no behaviour change for non-role logins).