Page MenuHomePhabricator

Add a rough HTTP header value parser
ClosedPublic

Authored by epriestley on Oct 10 2017, 8:23 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 25, 2:58 AM
Unknown Object (File)
Fri, Apr 19, 2:42 AM
Unknown Object (File)
Thu, Apr 11, 10:31 AM
Unknown Object (File)
Thu, Mar 28, 9:16 PM
Unknown Object (File)
Mar 1 2024, 4:34 PM
Unknown Object (File)
Feb 18 2024, 1:34 AM
Unknown Object (File)
Feb 12 2024, 4:05 AM
Unknown Object (File)
Jan 30 2024, 4:04 PM
Subscribers
None

Details

Summary

Ref T13008. Before we can disable enable_post_data_reading, we must be able to rebuild $_FILES ourselves. Before we can do this, we must be able to parse multipart/form-data requests. And, before we can do this, we must be able to parse complex HTTP headers, including these:

Content-Type: multipart/form-data; boundary="ABCDEFG"
Content-Disposition: form-data; name="something"; filename="something else"

Add a parser which can do this. The key parts are:

  • Picking the "boundary" out of the "Content-Type" header.
  • Picking all the stuff out of the "Content-Disposition" header for the actual multipart body.

This parser probably isn't perfect, but it will only be invoked when users upload vanilla files (e.g., "Change Profile Picture") so it's okay if it takes a while to sort out all the details.

Test Plan

Added unit tests, ran unit tests.

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

amckinley added inline comments.
src/aphront/headerparser/AphrontHTTPHeaderParser.php
128

Shouldn't this be if ($state != 'done')?

This revision is now accepted and ready to land.Oct 10 2017, 8:29 PM

For cases like Animal: zebra we'll end up in state "key" (since we never saw a ; or =), which is okay.

For cases like Animal: zebra= we'll end up in some other state but things turn out mostly okay for now, I think (zebra and zebra= have the same behavior).

This revision was automatically updated to reflect the committed changes.