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)
Wed, Dec 18, 3:23 AM
Unknown Object (File)
Fri, Dec 6, 11:15 PM
Unknown Object (File)
Tue, Dec 3, 1:09 PM
Unknown Object (File)
Wed, Nov 27, 9:58 PM
Unknown Object (File)
Mon, Nov 25, 1:46 PM
Unknown Object (File)
Sun, Nov 24, 12:27 AM
Unknown Object (File)
Oct 22 2024, 9:29 PM
Unknown Object (File)
Oct 21 2024, 8:55 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
Branch
post1
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 18667
Build 25145: Run Core Tests
Build 25144: arc lint + arc unit

Event Timeline

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

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.