Summary
Medplum's external identity provider callback may accept a redirect URI that merely begins with a registered URI instead of matching it exactly. An attacker who can influence the callback state may redirect login artifacts, including authorization codes, to an attacker-controlled endpoint when the configured URI can be extended into another origin.
Affected context
The issue occurs in Medplum deployments using the external identity provider login flow. Risk is present when redirect URI validation relies on prefix matching, registered redirect values are broad enough to be extended into another hostname, and callback state can be modified or trusted without sufficient integrity protection.
Exploit preconditions
- Attack surface: The external identity provider callback at
GET /auth/external - Required access: The ability to tamper with or influence the serialized login state, or otherwise cause the callback to process an attacker-selected redirect value
- Trigger point: Successful authentication through the external identity provider
- Why exploitation is possible: The callback accepts redirect URIs based on a prefix relationship and appends login artifacts to the supplied value without requiring an exact, trusted-origin match
Why this happens
The underlying bug is insufficient redirect URI validation combined with inadequate protection of callback state. Treating a redirect URI as valid because it starts with a registered value can allow a trusted prefix to be extended into a different host or origin. Trusting serialized state without verifying its integrity further permits attacker-controlled redirect data to reach the callback. This behavior maps primarily to CWE-601: URL Redirection to Untrusted Site, with CWE-345: Insufficient Verification of Data Authenticity also relevant to the state-handling weakness.
Potential impact
- An attacker could redirect authorization codes or login artifacts to an external endpoint
- User accounts or sessions could be exposed if leaked artifacts are usable
- OAuth or external identity provider flows could be redirected across origins
- The issue may enable account compromise depending on artifact validity and downstream protections
General mitigation guidance
Mitigation generally focuses on enforcing exact redirect URI registration and protecting the integrity of authentication state.
Common defensive patterns include:
- Require exact, canonical redirect URI matches rather than prefix or substring comparisons
- Bind redirect destinations to an allowlist of complete schemes, hosts, ports, and paths
- Reject redirects that cross the intended origin or contain ambiguous URL parsing forms
- Authenticate or cryptographically protect serialized state and validate it before use
- Avoid placing authorization artifacts in attacker-influenced destinations
- Apply least privilege and short lifetimes to authorization codes and related tokens
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis and code review checks for
startsWith, prefix, substring, or loosely normalized redirect URI comparisons - Review of OAuth and external-login callbacks for state integrity validation
- Tests using sibling hostnames, alternate ports, encoded characters, and path extensions
- Policy enforcement requiring exact redirect URI allowlists and same-origin validation
- Monitoring for authentication callbacks that redirect to domains outside the approved identity application set
Automated security testing and code review tools can help identify weak redirect validation and unprotected state handling.

