Summary
OpenEMR can grant write access to SMART/OAuth clients registered with read-only permissions because scope finalization does not properly check registered permissions. A client that can request a write scope may consequently be able to create, update, or delete appointments or patient data.
Affected context
The issue is in ScopeRepository::finalizeScopes() and ScopeEntity::containsScope() in OpenEMR. It becomes relevant when a SMART/OAuth client registered for a read scope can request the corresponding write scope, and the authorization flow does not enforce the client's registered permissions.
Exploit preconditions
- Attack surface: SMART/OAuth scope authorization in OpenEMR
- Required access: Ability to use a client registered with read-only permissions; the description does not establish that client registration itself is available to an attacker.
- Trigger point: Requesting a write scope during scope finalization
- Why exploitation is possible: Scope checking ignores the permissions registered for the client, allowing a read-only client to obtain a write scope.
Why this happens
The authorization logic does not reliably constrain requested scopes to the permissions registered for the client. ScopeEntity::containsScope() ignores those permissions, so ScopeRepository::finalizeScopes() can accept a write scope for a read-only client. This is an authorization enforcement failure mapped to CWE-863: Incorrect Authorization.
Potential impact
- Affected clients may be able to create or update appointments.
- A client may be able to modify or delete patient data.
- Unauthorized changes could affect the confidentiality, integrity, or availability of clinical records and workflows.
General mitigation guidance
Defensive patterns focus on enforcing authorization at the point where scopes are finalized:
- Compare every requested scope against the client's registered permissions and reject unregistered or excessive scopes.
- Use explicit, deny-by-default scope allowlists and consistent checks across authorization and token flows.
- Grant clients only the minimum permissions needed for their function.
- Keep read and write permissions distinct, and avoid treating a read permission as evidence of write authorization.
- Add tests that verify read-only clients cannot obtain write scopes.
How teams detect issues like this
Review scope-finalization code for checks that fail to bind requested scopes to client registrations. Look for scope containment or normalization logic that can accept broader permissions than the client was granted.
Monitor authorization and token events for read-only clients receiving write scopes, and enforce policies that reject scopes outside each client's registered allowlist. Static analysis and automated code review can help identify authorization checks that omit the relevant principal or permission set.

