File sanitization: Remove/replace leading hyphens

Created on 13 May 2024, 5 months ago

Problem/Motivation

I'm glad that filename sanitization/transliteration is in core. However, I noticed that filenames can have leading hyphens. This could be a security risk if someone runs shell commands containing wildcards in the directory and the filename becomes an argument to the command. Certainly, there are workarounds to run the commands more securely. Still, it seems like adding an option to remove leading hyphens, or incorporating that into the transliterate function, would be helpful and could prevent files with names like "-rf" or worse from having a disastrous effect.

Steps to reproduce

  1. Enable transliteration at /admin/config/media/file-system
  2. Upload a file with a leading hyphen

Proposed resolution

Trim leading hyphens from filenames, or replace them with a hyphen or the replacement character.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component
File system 

Last updated 1 day ago

Created by

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

Production build 0.71.5 2024