Summary
A logic error in @fastify/auth can incorrectly authorize requests when nested authentication strategies are combined with specific "or", "and", and "all" options. An attacker who satisfies only the final check in an intended AND group may bypass a stricter authorization requirement, such as administrative access.
Affected context
The issue affects @fastify/auth configurations that compose multiple strategies using nested arrays and the run: "all" option. It is relevant when an outer relation combines strategy groups and the evaluation order allows a failed earlier check to be discarded, including configurations using an outer or with nested AND groups or an outer and with nested OR groups.
Exploit preconditions
- Attack surface: Fastify routes protected by the @fastify/auth plugin
- Required access: Ability to send requests to an affected protected route; valid credentials for a weaker or later-evaluated strategy may be sufficient
- Trigger point: Authorization evaluation of nested strategy arrays with order-sensitive relation and run options
- Why exploitation is possible: A failed check can be silently replaced by the result of the final check in a group, causing the route guard to return an authorization result that does not represent every required condition
Why this happens
The vulnerability results from incorrect aggregation of authentication and authorization results when nested strategy groups are evaluated with the run: "all" behavior.
Instead of preserving the failure of an earlier required check, the implementation can allow the final strategy result to determine the group's outcome. This is an authorization logic flaw mapped primarily to CWE-285: Improper Authorization, with CWE-697: Incorrect Comparison describing the order-dependent evaluation behavior.
Potential impact
- Unauthorized users may access protected routes
- Users with limited credentials could gain administrative functionality
- API authorization boundaries may be bypassed
- Sensitive data or privileged operations could become accessible
- Downstream authorization assumptions may be weakened
General mitigation guidance
Mitigation generally focuses on making authorization composition explicit, order-independent, and fail-closed.
Common defensive patterns include:
- Avoiding ambiguous nested strategy combinations when a direct top-level composition expresses the policy more clearly
- Ensuring every required authorization condition must succeed before access is granted
- Removing
run: "all"where evaluating every strategy is not necessary - Designing group evaluation so failed required checks cannot be overwritten by later results
- Applying least privilege to route permissions and separating authentication from administrative authorization
- Adding tests for every permutation of strategy order, nesting, and relation settings
- Keeping authentication and authorization dependencies within supported security-maintained release lines
How teams detect issues like this
Organizations can identify this class of issue through:
- Static analysis and configuration review for nested authentication strategy arrays
- Code review checks for
relationandruncombinations that depend on evaluation order - Authorization tests that reorder strategies and verify identical outcomes
- Negative tests confirming that satisfying only one member of an AND group is insufficient
- Policy enforcement requiring explicit, fail-closed route authorization definitions
- Automated dependency and security review tools that flag affected library versions or authorization configuration patterns

