See the form API portion of https://drupal.org/SA-CORE-2014-001 and the form API portions of the patch in http://drupalcode.org/project/drupal.git/commitdiff/dc791ec5839b52c7616b....

This should be forward-ported to Drupal 8.

Since it was more of a security hardening than an actual security fix, possible backport to Drupal 6 can also be discussed here.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

In fact here's a Drupal 6 patch (basically the same people who worked on the Drupal 7 version in the S.A. also get credit for starting work on this one).

David_Rothstein’s picture

By the way, there was also some discussion in the security team about whether (in Drupal 8, where we can break APIs) the security hardening should default to being on for all programmatic form submissions, rather than off like in the security release.

David_Rothstein’s picture

Issue tags: +Needs backport to D7

Probably we should also add a paragraph of documentation to drupal_form_submit() about how/when to use this parameter (and that part would need backport to Drupal 7 as well).

mr.baileys’s picture

Assigned: Unassigned » mr.baileys
Status: Active » Needs review
FileSize
4.84 KB

Here is a forward-port to D8 with some basic tests. Stills needs the documentation paragraph explaining the existence and usage of programmed_bypass_access_check in FormBuilderInterface::submitForm().

pfrenssen’s picture

Status: Needs review » Needs work

Overall this looks very good and we really need this in D8.

  1. +++ b/core/lib/Drupal/Core/Form/FormBuilderInterface.php
    @@ -158,6 +158,12 @@ public function getForm($form_arg);
    +   *   - programmed_bypass_access_check: If TRUE, programmatic form submissions
    +   *     are processed without taking #access into account. Set this to FALSE
    +   *     when submitting a form programmatically with values that may have been
    +   *     input by the user executing the current request; this will cause
    +   *     #access to be respected as it would on a normal form submission.
    +   *     Defaults to TRUE.
    

    Great documentation!

  2. +++ b/core/modules/system/lib/Drupal/system/Tests/Form/ProgrammaticTest.php
    @@ -99,4 +99,31 @@ private function submitForm($values, $valid_input) {
    +    $this->assertTrue(isset($values['field_restricted']) && $values['field_restricted'] == 'dummy value', 'The value for the restricted field is stored correctly.');
    

    Using isset() to avoid notices being thrown is ingrained in every PHP developer's muscle memory, but has no place in a test. Use $this->assertEqual() instead to compare the two values.

  3. +++ b/core/modules/system/lib/Drupal/system/Tests/Form/ProgrammaticTest.php
    @@ -99,4 +99,31 @@ private function submitForm($values, $valid_input) {
    +    $this->assertTrue(!isset($values['field_restricted']) || $values['field_restricted'] != 'dummy value', 'The value for the restricted field is not stored.');
    +
    +  }
    

    This is actually testing two things, but which is the expected behaviour? I assume the value is expected to be empty, so you can use $this->assertFalse() on it.

    There is also a superfluous line of whitespace here.

mr.baileys’s picture

Status: Needs work » Needs review
FileSize
2.27 KB
5.39 KB

Addressed the remarks from #5

pfrenssen’s picture

Status: Needs review » Reviewed & tested by the community

It's looking great now, thanks!

catch’s picture

I think we should default this to FALSE rather than TRUE. Can we open a follow-up for that maybe? It won't be in the backport to 6.x so don't want to hold this up.

mr.baileys’s picture

catch’s picture

Status: Needs review » Reviewed & tested by the community

Those changes look good, thanks for opening the follow-up.

  • Commit a83352a on 8.x by catch:
    Issue #2174443 by mr.baileys, David_Rothstein: Add security hardening...
pfrenssen’s picture

Status: Reviewed & tested by the community » Fixed
catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)

Needs porting still I think.

pfrenssen’s picture

Version: 7.x-dev » 6.x-dev
Issue tags: -Needs backport to D7

Is already included in 7.x as a security fix in 7.26. Still needs to be backported to 6.x.

C-Logemann’s picture

Status: Patch (to be ported) » Needs review

We try to get the D6 version of the important services module running again and we have a security issue waiting of D6 port of this patch: #2189921: D6 Backport of "SA-CONTRIB-2014-007 - Services - Multiple access bypass vulnerabilities"

The test of D6 Backport patch by @David_Rothstein (#1) is passing. Needs some review now.

catch’s picture

Title: Add security hardening protection option for programmatic form submissions to Drupal 8 (and backport to Drupal 6?) » Add security hardening protection option for programmatic form submission
mr.baileys’s picture

Assigned: mr.baileys » Unassigned

JamesK’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #1 works fine and provides the necessary hardening.

C-Logemann’s picture

Thanks @JamesK for your review.

Can we please get this patch committed to D6?

Status: Reviewed & tested by the community » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.