We need to forward-port the arbitrary code execution fix for the installer from SA-CORE-2012-003 to Drupal 8.

(See the install.core.inc changes at http://drupalcode.org/project/drupal.git/commitdiff/b9127101ffeca819e74a...).

Most likely, it will be the same fix as Drupal 7, but we'll have to be a bit careful due to the Drupal 8 installer having different logic in this part of the code (to deal with verifying config directories in addition to settings.php).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

Issue tags: +Needs backport to D7

In addition, the fix committed to Drupal 7 contains a known (minor) regression.

In the case of an advanced user trying to install Drupal via a preconfigured settings.php, if the settings.php is preconfigured incorrectly (e.g., wrong database credentials) or if the database server doesn't meet the requirements for Drupal to be installed, then starting in Drupal 7.16 we're now displaying a "Drupal already installed" message to the screen, which in most cases will be incorrect.

I felt this regression was acceptable, given the severity of the security issue (and the fact that's an edge case which only advanced users can ever encounter). Also, fixing it would likely involve introducing new translatable strings, which aren't a good idea to add in a security release since by definition they won't be translated in time for the release.

However, we should ideally fix this (now that we're able to discuss it in the public issue queue) and backport it to Drupal 7 in a future release. The fix would likely involve some kind of more ambiguous message (because in this scenario we really can't differentiate between Drupal already installed and settings.php being incorrect), but one that gives the administrator more of a clue what the error is... without exposing too much information to an anonymous user who may encounter this error on an already-installed site.

If that becomes too complicated, though, we can split it off to another issue.

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.)

David_Rothstein’s picture

Trying that tag again...

David_Rothstein’s picture

Title: Fix installer PHP code execution issues from SA-CORE-2012-003 » Fix installer PHP code execution issues from SA-CORE-2012-003 (and backport anything to 7.x-dev as necessary)
bhauff’s picture

I am not sure if my situation is the same, but I am getting the Drupal is already installed errors when trying to use our custom install profile. The reason, I think, is because we define a secondary read only database in default.settings.php that we use for looking up related data. When settings.php is getting created, the secondary database is loaded from default.settings.php and Drupal thinks it is already installed.

Is there a better way to load this database definition in to settings.php, or another workaround without hacking the core change to ignore our particular database definition?

Thanks in advance.

David_Rothstein’s picture

@bhauff, so are you saying that before the installation, your databases array looks something like this?

$databases['secondary']['default'] = array(
  'driver' => ...,
  'database' => ....
  ...
);

But you don't want to pre-create the settings.php file itself? (Because if you pre-created the settings.php file itself, then for a particular site you could include the above as well as the standard $databases['default']['default'] in it all at the same time, and then you'd have no problem.)

I guess I can imagine that if your use case for this install profile is that it's only used on a particular server or set of servers, but you still want people to be able to install Drupal on their own, e.g. via the user interface... Kind of unusual, but I guess not out of the question.

One thing you might be able to do is wrap the above definition in something like if (!drupal_installation_attempted()), so that the secondary database doesn't become available until after the site is already installed (this assumes you don't actually need it while install.php is running).

It's also possible that the core patch was a bit too aggressive, and instead of checking !empty($GLOBALS['databases']) it could actually be changed to check !empty($GLOBALS['databases']['default']. I think that wouldn't have any security implications, but it would require a bit more thought to be sure.

bhauff’s picture

Hi David,

Thanks for the response, and before I explain my use case more I think that the core patch just checking the default database might be a great compromise.

We have a legacy database that all instances of our site use to look up reference data (dev on different developers local boxes, a shared dev on staging hardware, stage, and other test/temporary instances). We use drush site-install to install our instances (clone git repo, run drush site-install). We do copy our default.settings.php to settings.php before installation, this is done automatically by a small shell script. The default.settings.php file had the legacy database definition in it. Drush site-install creates the default database configuration based on a multitude of parameters that are passed to it (site name, dev box, current git user, etc.). We could pre-populate the default database configuration, but would be duplicating functionality that drush already provides. We do not ever install from the UI, only through drush site-install.

To work around this new restriction in drupal core we put our legacy database definition in a separate file in sites/default, and the shell script appends it to settings.php after installation is complete. It would be nice to not have to circumvent the install process as much, but at least we have a work around for now.

What is core's thoughts on a correct way to use drush site-install and automatically include additional database definitions?

Thanks,

Brandon

webchick’s picture

Status: Active » Needs review
FileSize
5.77 KB

Uploading the patch from gitweb to see what testbot has to say.

Status: Needs review » Needs work

The last submitted patch, b9127101ffeca819e74a03fa9f5a48d026c562e5.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review

This is a bit off-topic, but:
@bhauff: I think a less intrusive way of doing this, would be to use a Drush hook, that in some form manipulates the settings.php *post* installation. You could even create some sort of global.settings.php somewhere, that gets copied over. But you wouldn't break any assumptions that are made about default.settings.php.

tstoeckler’s picture

Status: Needs review » Needs work

That was a cross-post.

Berdir’s picture

Status: Needs work » Needs review
FileSize
1.08 KB

Updated the patch.

aspilicious’s picture

Don't we need the openid changes?

Berdir’s picture

David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

I reviewed and tested the Drupal 8 patch, and it looks good. The same fix does work for Drupal 8 as Drupal 7, because although the surrounding Drupal 8 code has logic for verifying config directories in addition to the settings.php database connection, it turns out they are both done separately, so we'll always reach the block of code in the above patch when the settings.php file fails to verify.

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.

We still have some other things to follow up on from above, but none of them are critical so let's get this committed to Drupal 8 first.

webchick’s picture

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

Yay! Committed and pushed to 8.x.

Btw, here's the commit string I used, which I crafted from the SA:

Issue #1816124 by Berdir, Damien Tournoud, David_Rothstein, pwolanin, chx: Fixed installer PHP code execution issues from SA-CORE-2012-003 (and backport anything to 7.x-dev as necessary).

Moving down to 7.x.

David_Rothstein’s picture

Title: Fix installer PHP code execution issues from SA-CORE-2012-003 (and backport anything to 7.x-dev as necessary) » (followups) Fix installer PHP code execution issues from SA-CORE-2012-003 (and backport anything to 7.x-dev as necessary)
Version: 7.x-dev » 8.x-dev
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 :)

dstol’s picture

sun’s picture

Title: (followups) Fix installer PHP code execution issues from SA-CORE-2012-003 (and backport anything to 7.x-dev as necessary) » Fix installer PHP code execution issues from SA-CORE-2012-003 (and backport anything to 7.x-dev as necessary)
Issue summary: View changes
Status: Active » Closed (fixed)

I've read all comments in this issue and the already existing #1887606: Possible DOS vulnerability due to anonymous users being able to trigger database installation tasks at install.php appears to be the only remaining possibility for improvement.