Skip to content

Escaping multipart/form-data #7575

Open

Description

@michaelweiser

https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#multipart-form-data

For field names and filenames for file fields, the result of the encoding in the previous bullet point must be escaped by replacing any 0x0A (LF) bytes with the byte sequence %0A, 0x0D (CR) with %0D and 0x22 (") with %22. The user agent must not perform any other escapes.

Doesn't that mean that no file (or field) name can ever legitimately contain character sequences that encode to byte sequences %0A, %0D or %22? (For most if not all encodings it'll be these character sequences exactly.)

The sender will apply no escaping but the receiving end will unescape them into bytes 0x0A, 0x0D and 0x22 respectively. From there they'll not decode back into the original character sequences, i.e. the filename will end up corrupted. For example, 100%0Applejuice.pdf would become 100<linefeed>pplejuice.pdf.

Should escaping of the escape character (0x25, %) as %25 be added here?

Activity

  1. annevk commented on Feb 16, 2022

    @annevk
    Member
  2. added
    topic: forms
    on Feb 16, 2022
  3. andreubotella commented on Feb 16, 2022

    @andreubotella
    Member

    Chromium and WebKit have both had this behavior for many years, and they don't escape the percent sign. Given the relative rarity of such filenames, I suspect this hasn't been an issue in practice (although it seems like WebKit might consider this worth looking into).

    @cdumez @mfreed7 @smaug----

  4. smaug---- commented on Feb 16, 2022

    @smaug----

    Sounds like an edge case, but something which probably should and could be fixed.

  5. mfreed7 commented on Mar 21, 2022

    @mfreed7
    Contributor

    This was reported to Chromium a few days ago, based on a bug filed against PHP.

    I do agree that the current spec (and behavior) seems a bit odd here. It feels like we should add just one more explicit escape for filenames, from % --> %25. That would allow folks to distinguish between ".txt and %22.txt.

    I suspect the compat story wouldn't be terrible in making this change, but there are no guarantees that it won't break something. I suppose we could add a use counter for finding % in a filename.

  6. added
    agenda+
    on Mar 21, 2022
  7. removed
    agenda+
    on Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: forms

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions