We need to forward-port the OpenID security fix from SA-CORE-2012-003 to Drupal 8.

(See the OpenID module changes in http://drupalcode.org/project/drupal.git/commitdiff/b9127101ffeca819e74a...).

For Drupal 8, it's possible we can do a bit of a different fix since we can rely on the PHP function libxml_disable_entity_loader() always existing (which we couldn't do for all supported PHP versions in Drupal 7).

Comments

David_Rothstein’s picture

Let's also tag this issue as a D7 release blocker, since although the original fix from Drupal 7.16 was merged in to 7.x-dev already, we want to double check that the latest 7.x code is not vulnerable before doing the next bugfix release of Drupal core.

(In this particular case, I think the chance is around 0% that this is the case, but I'm tagging it anyway to keep track of it and because in theory it is always a possibility due to differences between the previous stable release that the security release was made from, and the current code in 7.x-dev. Per the new release policy, we are now able to do this step in the public issue queue as a followup, rather than having it be part of the security team's private work.)

berdir’s picture

Status: Active » Needs review
StatusFileSize
new3.57 KB

Re-rolled patch.

Simplified the check, not sure if we still need that doctype check, left it there for now.

Status: Needs review » Needs work

The last submitted patch, openid-security-fix-1816136-2.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new3.6 KB

Added a drupalLogout(), should pass now.

David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.6 KB

I reviewed and tested this patch and it seemed to work fine. (I'm attaching a version that fixes a code comment typo - missing capital letter at the beginning of a sentence - but no other changes.) This should be good to go for Drupal 8.

I also double checked that the latest 7.x-dev code isn't subject to this vulnerability, so I'm removing that tag as well.

For Drupal 8, we likely could rely on libxml_disable_entity_loader() entirely, but things get a little tricky there (it would require further refactoring to make sure the correct error messages still display and the tests still pass), so no real need to do it here. Removing the doctype entirely should always work anyway.

I was also a bit curious about why the Drupal 8 tests needed to specify the form ID here but the Drupal 7 ones didn't:

+    $this->drupalPost('', $edit, t('Log in'), array(), array(), 'openid-login-form');

But @Berdir pointed out to me that it's because the OpenID forms were refactored in Drupal 8 in #1538462: Cannot log in with OpenID due to "required" attribute so that they're now separate from the user login form.

David_Rothstein’s picture

There's actually a minor bug here:

+  // Protect against malicious doctype declarations and other unexpected entity
+  // loading.
+  $load_entities = libxml_disable_entity_loader(TRUE);
.....
+  // Since DOCTYPE declarations from an untrusted source could be malicious, we
+  // stop parsing here and treat the XML as invalid since XRDS documents do not
+  // require, and are not expected to have, a DOCTYPE.
+  if (isset($dom->doctype)) {
+    return array();
+  }
.....
+  // Return the LIBXML options to the previous state before returning.
+  libxml_disable_entity_loader($load_entities);
+
   return $services;
 }

Since the first return doesn't reset the libxml options to their original state, only the second one.

But that's very minor and exists in Drupal 7 too, so I think this is still RTBC.

webchick’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Yeah, let's get this sucker in and then we can file that as a minor follow-up.

Committed and pushed to 8.x. Back to 7.x.

I used the following commit message, crafted from the SA:

Issue #1816136 by Berdir, David_Rothstein, ubercomp, c960657, wojtha, fgm, pwolanin, Damien Tournoud, Heine: Fixed OpenID vulnerability from SA-CORE-2012-003 (and backport anything to 7.x-dev as necessary).

David_Rothstein’s picture

Title: Fix OpenID vulnerability from SA-CORE-2012-003 (and backport anything to 7.x-dev as necessary) » (followups) Fix OpenID vulnerability from SA-CORE-2012-003 (and backport anything to 7.x-dev as necessary)
Version: 7.x-dev » 8.x-dev
Category: bug » task
Priority: Critical » Normal
Status: Patch (to be ported) » Active

There are no longer any security issues in 7.x here, so moving back to 8.x for possible followups discussed above - or it could be a separate issue but I don't have the energy to file one right now :)

swentel’s picture

Project: Drupal core » OpenID
Version: 8.x-dev » master
Component: openid.module » OpenID Client

Moving to the openid module since the module is not in D8 anymore.