Repeatable: Always
Steps to repeat:
1. run drush cr on server
2. Try to log in with /saml/login

Expected Results:
User is logged in configured saml service, returned to drupal and given a valid drupal session

Actual Results:
User is logged in to configured saml service and returned to drupal, but receives the error message below at /saml/acs:

The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Please ensure you are not rendering content too early.

Refreshing the page will show drupal with the correct session, but the error is displayed for some reason.

Comments

nicolas-mosch created an issue. See original summary.

roderik’s picture

@$^@%#%$$%@$%#$%#$ cacheability metadata and URLs...

(At least digesting all the discussion around it in the past month, got me to a point where I'm not despairing after your bug report.)

So... I can't reproduce this.

1)
First things first: I discovered an error in the code while typing up this answer. Does making the following (temporary) change help?

diff --git a/src/EventSubscriber/AccessDeniedSubscriber.php b/src/EventSubscriber/AccessDeniedSubscriber.php
index 9f3202a..b4c36b2 100644
--- a/src/EventSubscriber/AccessDeniedSubscriber.php
+++ b/src/EventSubscriber/AccessDeniedSubscriber.php
@@ -47,7 +47,7 @@ class AccessDeniedSubscriber implements EventSubscriberInterface {
         case 'samlauth.saml_controller_login':
         case 'samlauth.saml_controller_acs':
           // Redirect an authenticated user to the profile page.
-          $url = Url::fromRoute('entity.user.canonical', ['user' => $this->account->id()])->toString();
+          $url = Url::fromRoute('entity.user.canonical', ['user' => $this->account->id()])->toString(TRUE)->getGeneratedUrl();
           $event->setResponse(new LocalRedirectResponse($url));
       }
     }

2) If that's not it:

From all I know right now, this is not directly an issue with the code in the samlauth module (although it is possible for the samlauth module to take measures to prevent it). I instead suspect code that is executed on an event or a hook that is called by /saml/acs.

So:

  • Do you have any code (custom module, likely) on the 'USER_SYNC' event subscriber? (Does it call Url::toString()?) Can you disable it and test if you still get the exception?
  • Do you have a "Login redirect URL" configured? Does it contain a token?
  • Any contrib/custom modules that you know execute code during saving the user (when its properties are synchronized)? Can you shut them off and test if you still get the exception?

If a cause can be pinpointed, I'd love to know, because I want to dive into this URL/Leaked Metadata mess.

3)
Regardless, I'll have a patch soonish. First attempt failed, so I'll need to do a little more work (hopefully) tomorrow.

nicolas-mosch’s picture

Hello Roderik,

thank you very much for your quick reply. Indeed you are correct; I tried uninstalling some modules and reproducing the issue and it appears that after uninstalling the LDAP module (the 'User' module from LDAP in particular) I could no longer reproduce it.

I will try to find the source of the problem in their code, although any help would be greatly appreciated if possible as I am not exactly sure what I am looking for.

roderik’s picture

Thank you nicolas-mosch.

Looking at the bug in the LDAP/user module code yourself is optional, because samlauth likely can and should prevent the LDAP/user module from having this effect.

I personally still want to check out their code and see if a bug report should be filed, because I spent some time trying to work out the depth of the problem surrounding this "Leaked metadata" exception in detail, and this is a practical example where I can verify practical obstacles.

But if you really want to know:

Fixing the samlauth module to work around the dangers, will be easier than reading all this. I just need time to sit down and continue, one of these evenings.

  • roderik committed 0cffef3 on 8.x-3.x
    Issue #3050122 by roderik: protect against code in user_* hooks (and our...
roderik’s picture

Well, that took longer than I hoped... Had another half year break on working on this module.

I've now decided which way I want to solve this, and pushed a fix to the 3.x-dev branch.

What you can also do, instead of using this -dev branch, is try to apply #3092008: Possible fix to "leaked metadata" exception to the ldap_user module, and see if the issue goes away. Because I've uploaded a patch for what I think is the code causing the exception, but haven't tested it. So I don't know if it's complete.

roderik’s picture

Status: Active » Needs review
roderik’s picture

Status: Needs review » Fixed

Since there have been no further reports about leaked metadata, I'll assume (admittedly for the third time) that the code is now handling all possible situations correctly.

Status: Fixed » Closed (fixed)

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