Problem/Motivation

When the simple_oauth module is installed, authenticated users with valid session cookies are incorrectly treated as anonymous on certain requests, particularly those with role-based access restrictions (e.g., Page
Manager pages with user role conditions).

The issue occurs because `SimpleOauthAuthenticationProvider::applies()` performs route lookups (via `pathValidator->getUrlIfValidWithoutAccessCheck()`) **before** checking if the request contains an OAuth2 Bearer token.
Since simple_oauth has authentication provider priority 35 (higher than cookie authentication's priority 0), these route lookups happen before cookie authentication can resolve the user session, interfering with the
authentication flow.

Proposed resolution

Reorder the logic in `SimpleOauthAuthenticationProvider::applies()` to:
1. Check for OAuth2 Bearer token FIRST
2. Return FALSE immediately if no Bearer token is present
3. Only perform route lookups if the request IS an OAuth2 request

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alorenc created an issue. See original summary.

alorenc’s picture

Assigned: Unassigned » alorenc

alorenc’s picture

alorenc’s picture

Priority: Normal » Major
alorenc’s picture

## Performance impact

**Before fix:** Route lookups (`pathValidator->getUrlIfValidWithoutAccessCheck()` + `routeProvider->getRouteByName()`) occur on EVERY request, regardless of whether OAuth is being used.

**After fix:** Route lookups only occur when a Bearer token is present (typically <1% of requests on most sites). For non-OAuth requests, the method returns FALSE immediately after a simple header check.

alorenc’s picture

Assigned: alorenc » Unassigned
Status: Active » Needs review
claudiu.cristea’s picture

Priority: Major » Critical

I can reproduce the issue with some page_manager routes. After installing simple_oauth, suddenly, the routes created by page_manager, normally accessible by authenticated user, are returning 403. I see this as Critical as breaks an existing site.

claudiu.cristea’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thank you for the fix. I have tested manually the MR and works as expect. However, given the impact of this bug, I'm sure it deserves a regression test.

On MR I've also proposed some minor improvements to documentation.

bojan_dev made their first commit to this issue’s fork.

bojan_dev’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

I have addressed the feedback, please review.

claudiu.cristea’s picture

Assigned: Unassigned » claudiu.cristea

I'm going to review the changes

claudiu.cristea’s picture

Assigned: claudiu.cristea » Unassigned
Status: Needs review » Needs work

We need a test that replicates the bug when the fix is not applied

bojan_dev’s picture

Status: Needs work » Needs review

Picked up the feedback, please review again.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

This looks good, thank you all

@bojan_dev, if merged, could you, please, cut a new release?

bojan_dev’s picture

Status: Reviewed & tested by the community » Fixed

I just released 6.0.5 with the fix.

Nice work all!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.