Add phtml files to the list of potentially malicious extensions

Created on 12 May 2021, about 3 years ago
Updated 4 May 2023, about 1 year ago

Problem/Motivation

(Note: this was originally reported at security.drupal.org, but the Sec Team decided it can be handled in public since the circumstances that trigger it are exceedingly rare).

I'd never heard of "phtml" files before. ;) Then I found this in my (mostly) default httpd.conf from MAMP on my local dev box:

AddHandler application/x-httpd-php .php .phtml

Huh? ;) Core doesn't treat these as particularly malicious files.

So IF...

  1. You configured a file upload to allow 'phtml' files
  2. And your httpd.conf contains the above
  3. And for whatever reason the .htaccess got removed from your public files dir (or wasn't created in the first place, etc)

THEN anyone who can access this file upload can run PHP on your server.

Steps to reproduce

  1. Install Drupal core
  2. Add a file field to one of your content types.
  3. Configure that field to allow .phtml file uploads.
  4. Configure your httpd.conf file to include:
    AddHandler application/x-httpd-php .php .phtml
    
  5. Remove the .htaccess file that should be in your public files directory.
  6. Create a rce.phtml file with the following content:
    <?php
     echo "You've been hacked";
    ?>
    
  7. Upload that file to the site.
  8. Click on a link to the file.

Expected result

You should see the full contents of the PHP file as text:

<?php
 echo "You've been hacked";
?>

Actual result

The PHP has been interpreted and remote code execution is possible:

You've been hacked

Proposed resolution

Add 'phtml' to the list of extensions that we give special treatment to for .txt renaming if allow_insecure_uploads is FALSE.

Remaining tasks

  1. Reviews / refinements.
  2. RTBC.
  3. Commit.

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Fixed

Version

9.5

Component
File systemΒ  β†’

Last updated about 23 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States dww

Live updates comments and jobs are added and updated live.
  • Security improvements

    It makes Drupal less vulnerable to abuse or misuse. Note, this is the preferred tag, though the Security tag has a large body of issues tagged to it. Do NOT publicly disclose security vulnerabilities; contact the security team instead. Anyone (whether security team or not) can apply this tag to security improvements that do not directly present a vulnerability e.g. hardening an API to add filtering to reduce a common mistake in contributed modules.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024