Summary
Stalwart Mail Server may accept an OAuth redirect destination without checking it against a registered client destination in its default configuration. An attacker who can initiate an authorization request with a destination they control may capture a valid authorization code and exchange it for access and refresh tokens after the account holder authenticates.
Affected context
The issue occurs in OAuth authorization flows where client authentication is disabled and redirect destinations are therefore not constrained by registered client metadata. The supplied destination is retained with the authorization code, returned through the login flow, and later accepted by the token endpoint when it matches the value recorded with that code.
Exploit preconditions
- Attack surface: OAuth authorization and login endpoints
- Required access: Ability to construct or submit an OAuth authorization request; the victim must authenticate to the affected account
- Trigger point: Processing the authorization request and redirecting the browser after authentication
- Why exploitation is possible: The default validation path can return success without matching the redirect against a registered destination, while the token exchange validates only consistency with the stored value
Why this happens
The underlying bug is insufficient validation of an OAuth redirect URI, mapping to CWE-601: URL Redirection to Untrusted Site. When client authentication is disabled, the validation routine accepts the supplied destination instead of requiring an exact match against an approved registration. The authorization code is then bound to that attacker-controlled destination, allowing the code to be delivered outside the intended trust boundary.
Potential impact
- An attacker could capture an authorization code
- The attacker may exchange the code for access and refresh tokens
- Unauthorized parties could read the affected account's mail
- Compromised tokens could enable persistent access until revoked or expired
- The issue could facilitate privacy breaches and account-level abuse
General mitigation guidance
Mitigation generally focuses on making redirect validation mandatory and
fail-closed.
Common defensive patterns include:
- Require exact matching against pre-registered redirect destinations
- Avoid accepting arbitrary redirect values from authorization requests
- Treat client authentication and redirect registration as security controls
- Use narrowly scoped, short-lived authorization codes and tokens
- Apply least privilege to OAuth clients and limit mail access scopes
- Bind authorization codes to the intended client and other relevant request context
- Provide token revocation and monitoring controls for suspicious OAuth activity
How teams detect issues like this
Organizations can look for:
- Static analysis findings where redirect parameters are accepted without allowlist comparison
- Code review signals showing validation bypasses when client authentication is disabled
- OAuth tests that submit unregistered, cross-origin, or attacker-controlled redirect destinations
- Policy checks requiring exact redirect URI matching and fail-closed behavior
- Logs containing unusual redirect destinations, repeated authorization requests, or unexpected token exchanges
- Automated security testing or code review tools that model OAuth redirect-flow misuse

