Problem/Motivation
This issue has been discussed with the Drupal Security Team, and approved for handling in public as there is no direct vulnerability / exploit.
It's possible to abuse the config sync import functionality in order to upload malicious files.
In order to access the functionality, a user must have one or more restricted permissions.
At present \Drupal\config\Form\ConfigImportForm will extract the content of an uploaded tarball into the config_sync_directory without any filtering or sanitisation of file attributes.
This means it's possible to include e.g. malicious executable files in the tarball and these will be extracted to the sync directory.
A bad actor would then need a way of actually executing those malicious files, but getting them onto the webserver at a predictable location - with the executable bit in tact - could be one step in a chained attack.
Note that it should not be possible to use e.g. directory traversal to extract a file outside the sync directory, but this depends on the implementation in the PEAR Archive_Tar library. There has been at least one relevant vulnerability in the library in the past (e.g. https://github.com/advisories/GHSA-p8q8-jfcv-g2h2 ).
Steps to reproduce
Use the tarball import functionality at /admin/config/development/configuration/full/import to upload a tarball with content other than valid .yml configuration exports.
For example, an executable shell script within the tarball will be extracted into the sync directory.
Proposed resolution
The tarball import should only extract what appear to be valid .yml config files.
It should also sanitise the permissions of imported files; for example ensuring that they are not executable.
Remaining tasks
MR / review / merge etc..
User interface changes
I don't think we need to present error messages when there are files in the tarball that will not be extracted, or permissions that will be sanitised?
Introduced terminology
n/a
API changes
n/a
Data model changes
n/a
Release notes snippet
I don't think this needs a release note, as there is no change to the legitimate functionality.
Issue fork drupal-3526769
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3526769-avoid-abuse-of
changes, plain diff MR !12251
Comments
Comment #3
mcdruid commentedComment #4
mcdruid commentedComment #5
mcdruid commentedLooks like it's legitimate to have subdirectories within the tarball, based on
\Drupal\Tests\config\Functional\ConfigExportImportUITest::testExportImportCollections.I'd initially assumed there was only ever a flat list of yml files.
Comment #6
mcdruid commentedExisting tests pass with the changes in the MR.
We should add one or more tests that show:
Comment #7
mcdruid commentedAdded a basic test that verifies a shell script cannot be smuggled into a config import tarball, and checks that files are not executable after import (even when they are inside the tarball).
I think this needs to be a functional test, as the changes being made are in the processing of the import form on submission.
Comment #8
mcdruid commentedHere's the contents of the test tarball:
I was wondering about putting that in a comment in the test to save anyone having to examine it themselves.. but perhaps that just risks getting out of sync with the fixture file, and might not be necessary / helpful anyway.
Comment #9
mcdruid commentedVerified that the test-only job fails as expected:
https://git.drupalcode.org/issue/drupal-3526769/-/jobs/5685661
..but tests pass with the changes.
Comment #10
smustgrave commentedI would agree, not sure how many users import this way but imagine they are aware of the other files if they use this approach.
Maybe translations?
Test-only feature has already been ran
Which seems to fail at a valid assertion for this issue.
Changes themselves look fine to me (least no objection)
Comment #11
catchThis looks good to me.
I briefly thought we should warn, but it's far more likely someone would upload their own malicious tarball than persuade someone else to do so, do we want to tell the attacker what we did? And also if someone accidentally bundles up a .orig file or something else weird, do they really need to know we ignored it?
Committed/pushed to 11.x and cherry-picked to 11.2.x, 10.6.x and 10.5.x, thanks!
Comment #17
catch