Since #2923213: Use session manager instead of accessing $_SESSION directly connecting an account on the Connected accounts page (/user/1/connected-accounts) no longer works and results in an access denied page on multilingual websites.

This page results in an access denied page since the first time /user/1/connected-accounts is visited and checked if the user has access to this page. Then the user will redirect to en/user/1/connected-accounts (probably because I have the URL detection method enabled) and access is checked again.

  public function access(): AccessResultInterface {
    // Confirm anti-forgery state token. This round-trip verification helps to
    // ensure that the user, not a malicious script, is making the request.
    $request = $this->requestStack->getCurrentRequest();
    $state_token = $request->get('state');
    if ($state_token && $this->stateToken->confirm($state_token)) {
      return AccessResult::allowed();
    }
    return AccessResult::forbidden();
  }

In the access method the state value is retrieved and removed from the session. So the second time, the value is retrieved again from the session, but is no longer available, which will result in an access denied error.

CommentFileSizeAuthor
#2 3205369-2.patch512 bytesJeroenT
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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JeroenT created an issue. See original summary.

JeroenT’s picture

Status: Active » Needs review
FileSize
512 bytes

The patch attached is a quickfix and solves the problem. But the state value is no longer cleared from the session.

jcnventura’s picture

Before I moved everything to the OpenIDConnectSession class, the state token was being cleared on it's own somewhere else. I think this is partly the reason for that. I'll need to add back the removeStateToken method to that class. The other session usages clear the session just after reading it, so I decided to combine it into one.

jcnventura’s picture

Title: Connect account user page no longer works on multilingual website » State token removed from session before authorization is complete

  • jcnventura authored 6d56b91 on 2.x
    Issue #3205369 by JeroenT, jcnventura: State token removed from session...
jcnventura’s picture

Status: Needs review » Fixed

I added a 'clear' flag to the retrieveZZ() methods of the session class. The getStateToken wil use that flag set to FALSE in the only placed it was being called, and I've added a new call to the same method with the default value of TRUE where the old unset($_SESSION) used to be.

Status: Fixed » Closed (fixed)

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

Ravi Shankar Karnati’s picture

Team - Am facing the same issue for 8.x-1.2, can i have any fix for it ?
Thanks in advance.