Stream wrappers don't decode url encoded URIs

Created on 23 March 2012, over 12 years ago
Updated 3 September 2023, about 1 year ago

Problem/Motivation

It looks like it is valid to pass a url encoded path/uri to stream wrapper implementations. We are currently not handling this. As opposed to most internal file functions, libxml seems to encode the path, so simplexml_load_file('temporary:://some file.xml') fails.

See https://bugs.php.net/bug.php?id=61469 for background.

Proposed resolution

Use rawurldecode() on the path.

Remaining tasks

Write a test and the fix

User interface changes

-

API changes

-

🐛 Bug report
Status

Needs work

Version

9.5

Component
File system 

Last updated about 2 hours ago

Created by

🇨🇭Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇺🇸United States Amber Himes Matz Portland, OR USA

    We triaged this in Bug Smash.

    Is this still an issue? It would be great to add a failing test to prove the issue.

    Also adding tags for re-roll and tests.

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Custom Commands Failed
  • 🇮🇳India vsujeetkumar Delhi

    Re-roll patch created against 9.5.x, Also added Test case that is missing in #5, It is based on #1. Please have a look.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    19:18
    18:23
    Running
  • 🇮🇳India vsujeetkumar Delhi

    Fixed CCF issues, Please have a look.

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States cmlara

    Considering how long this issue has existed I would assert that this would be excessively disruptive to implement now. And if it were to be implemented it also needs to be done in a manner that also rewrites EVERY reference to a file in Drupal to be urlencoded and requires a new base class for streamWrappers.

    test#file.txt is NOT the same as test%23file.txt on disk (at least for *nix) having the streamWrapper attempt to coerce a decode now would be inappropriate and could lead to data loss and data leakage.

    Sample on Linux with an ext4 filesystem:

    $ mkdir test_files
    $ cd test_files/
    $ touch 'test#file.txt'
    $ touch 'test%23file.txt'
    $ ls -alh
    ..
    -rw-rw-r--   1 user group    0 Sep  2 23:45 test%23file.txt
    -rw-rw-r--   1 user group    0 Sep  2 23:45 test#file.txt
    

    Key note is that %23 passed through rawurldecode() would be converted to # causing an incorrect file access, and blocking access to the intended file.

    Adding the security review tag for the fact that this could lead to access bypass issues inside of core/contrib by using urlencoding to make the request appear to be for a different file.

  • 🇬🇧United Kingdom catch

    I think I might have hit this in 📌 Tidy up URL generation for asset aggregates Needs work .

Production build 0.71.5 2024