Make WordPress Core

Opened 2 months ago

Last modified 8 weeks ago

#66125 assigned defect (bug)

Upload file with double-quote in filename

Reported by: sgastard Owned by: sgastard
Priority: normal Milestone: Awaiting Review
Component: Upload Version: 7.1
Severity: normal Keywords: has-patch changes-requested
Cc: Focuses:

Description

Uploading a file like "test".png results in a filename like 22test22.png on the server and a matching URL. The file remains accessible.

Attachments (1)

Capture d’écran 2026-09-17 à 11.53.16.png​ (42.4 KB ) - added by sgastard 2 months ago.

Download all attachments as: .zip

Change History (8)

This ticket was mentioned in ​PR #13574 on ​WordPress/wordpress-develop by ​@sgastard.


2 months ago
#1

  • Keywords has-patch added

Opened from the WordPress Contributor Toolkit.

This ticket was mentioned in ​PR #13575 on ​WordPress/wordpress-develop by ​@sgastard.


2 months ago
#2

Opened from the WordPress Contributor Toolkit.

#3 @sgastard
2 months ago

  • Keywords has-patch removed
  • Owner set to sgastard
  • Status new → assigned

This ticket was mentioned in ​PR #13579 on ​WordPress/wordpress-develop by ​@sgastard.


2 months ago
#4

  • Keywords has-patch added

Clean filename of uploaded file when the name contains quote (")

#5 @westonruter
8 weeks ago

  • Keywords needs-unit-tests added

#6 @sgastard
8 weeks ago

  • Keywords needs-unit-tests removed

#7 @westonruter
8 weeks ago

  • Keywords changes-requested added

Re-sharing my ​PR review here for visibility:

I wonder if sanitize_file_name() is the best location to do these replacements. What if I have a image that depicts the modulo operator in PHP. I create an illustration: 220 % 22 = 0. The file name I use is 220%22.png. With the changes here, this will become 220.png, which is not helpful.

I think the URL decoding is being done at the wrong layer. The decoding should be done at a layer above at the point where we _know_ the filename _is_ URL encoded.

In that way, if I have a URL-encoded filename for the above example, it is 220%2522.png and it should be decoded into 220%22.png and this should pass-through to be used as the file name. Or else, if % is not a permitted character, then at this point it can be replaced with - or mod or something else which is safe for the filesystem.

Note: See TracTickets for help on using tickets.