I'm getting the following error:

Executable PHP in files directory

...

The .htaccess file exists but does not contain the correct content. It is possible it's been maliciously altered.

I've manually compared the contents of sites/default/files/.htaccess with the output of file_htaccess_lines function, and it matches perfectly.

The .htaccess file is 644, and the files folder is 755.

The code in security_review.inc on line 642 reads:

    // Text from includes/file.inc.
    $expected = "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks";
    if ($contents !== $expected) {
      $result = FALSE;
      $check_result_value[] = 'incorrect_htaccess';
    }

This code is too brittle, and too easy to get out of sync with core.

The following code compares the entire output of file_htaccess_lines() function with the actual file contents (stripping whitespace, which was causing issues for me as well).

    // Text from includes/file.inc.
    $expected = file_htaccess_lines(FALSE);
    if (trim($contents) !== trim($expected)) {
      $result = FALSE;
      $check_result_value[] = 'incorrect_htaccess';
    }

Patch to follow.

Comments

jwilson3’s picture

Status: Active » Needs review
StatusFileSize
new780 bytes
coltrane’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs review » Needs work

Hi. Thank you for this, but please update your patch against 7.x-1.x-dev which holds #2141217: Update htaccess content check to support Drupal 7.24

I think the only difference is the trim().

jwilson3’s picture

Whoops should have checked dev first, here you go.

  • Commit 6845579 on 7.x-1.x authored by jwilson3, committed by coltrane:
    Issue #2242609 by jwilson3: Trim whitespace in htaccess content check
    
coltrane’s picture

Status: Needs work » Fixed

Committed. Thanks!

I plan to get a new stable release out soon.

Status: Fixed » Closed (fixed)

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