Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart-Form-Data in akka-http, missing quotes in Content-Disposition field #386

Closed
ktoso opened this issue Oct 12, 2016 · 13 comments
Closed
Labels
3 - in progress Someone is working on this ticket discuss Tickets that need some discussion before proceeding t:core Issues related to the akka-http-core module
Milestone

Comments

@ktoso
Copy link
Member

ktoso commented Oct 12, 2016

Issue by KrzyMucha
Wednesday Oct 12, 2016 at 08:05 GMT
Originally opened as akka/akka#21656


When we use akka-http for http request with following code:

Multipart
            .FormData(Multipart.FormData.BodyPart("file",
                HttpEntity.Strict(MediaTypes.`image/jpeg`, ByteString("test")), Map("filename" -> "somefile.jpeg"))).toEntity()

Then Http request is as follows

User-Agent: [akka-http/2.4.8]
Transfer-Encoding: [chunked]
Host: [localhost:8089]
Content-Type: [multipart/form-data; boundary=xWtacaNwjOWLKFExaR8fOv6Q; charset=UTF-8]

--xWtacaNwjOWLKFExaR8fOv6Q
Content-Type: image/jpeg
Content-Disposition: form-data; filename=somefile.jpeg; name=file

test
--xWtacaNwjOWLKFExaR8fOv6Q--

Parameters filename and file are without quotation marks. However following HTTP specification this params should be quoted. As result some servers (ex. "django" app) are not able to see attached files.

@ktoso
Copy link
Member Author

ktoso commented Oct 12, 2016

Comment by ktoso
Wednesday Oct 12, 2016 at 08:10 GMT


Please open the issue on github.com/akka/akka-http instead, sinve the project has moved.

AFAIR there is no need to quote these according to the https://tools.ietf.org/html/rfc6266 spec

     filename-parm       = "filename" "=" value
                         | "filename*" "=" ext-value

       value                   = token | quoted-string

notice the | there.

Let's please continue in the right repo.

@ktoso ktoso changed the title [CLOSED] Multipart-Form-Data in akka-http, missing quotes in Content-Disposition field Multipart-Form-Data in akka-http, missing quotes in Content-Disposition field Oct 12, 2016
@ktoso ktoso added the discuss Tickets that need some discussion before proceeding label Oct 12, 2016
@ktoso
Copy link
Member Author

ktoso commented Oct 12, 2016

Issue by KrzyMucha
Wednesday Oct 12, 2016 at 08:05 GMT
Originally opened as #387


Information about requirement I found here: https://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html, paragraph 19.5.1 Content-Disposition

filename-parm = "filename" "=" quoted-string
disp-extension-parm = token "=" ( token | quoted-string )

@ktoso
Copy link
Member Author

ktoso commented Oct 12, 2016

Seems you're right, according to https://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1 @KrzyMucha.
Would you be able to contribute a fix for this? It's relatively simple, I'm happy to help if you need pointers to get started.

@KrzyMucha
Copy link
Contributor

I can do fix

@jrudolph
Copy link
Member

I'm pretty sure there should be a related ticket lurking somewhere.

@jrudolph
Copy link
Member

jrudolph commented Oct 12, 2016

This seems to be a duplicate of akka/akka#18788. There we concluded that RFC 2616 is not the most recent one and RFC 6266 also allows filename parameter values without quotes. Still, if this was only recently changed (2011) it might make sense to add extra quotes even if they are not strictly required by the latest spec.

@jrudolph
Copy link
Member

Appendix A of RFC 6266 says:

   o  RFC 2616 only allows "quoted-string" for the filename parameter.
      This would be an exceptional parameter syntax, and also doesn't
      reflect actual use.

@jrudolph
Copy link
Member

Also looking at this stackoverflow answer which seems to imply that browsers also seem to be very confused about what they generate. (Though I guess it would need to be re-checked with recent browsers.)

@KrzyMucha
Copy link
Contributor

KrzyMucha commented Oct 12, 2016

What I found is that other clients (I checked curl and dispatch.io) put values of parameters name and filename in quoted marks, like this:

Content-Disposition: form-data; name="file"; filename="6117776844.jpeg"

Should the fix enforce similar behaviour for akka-http?

@ktoso
Copy link
Member Author

ktoso commented Oct 12, 2016

Seems that would be perhaps safer than now.
As the linked discussion said it "Browser compatibility is a mess." :-/

@ktoso ktoso added 1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted t:core Issues related to the akka-http-core module t:http:core and removed t:core Issues related to the akka-http-core module labels Oct 12, 2016
@jrudolph jrudolph added t:core Issues related to the akka-http-core module and removed t:http:core labels Nov 2, 2016
KrzyMucha pushed a commit to KrzyMucha/akka-http that referenced this issue Nov 3, 2016
@KrzyMucha
Copy link
Contributor

@ktoso I created pull request for this, however I made some mess before (first time on github doing this). Anyway doing my best :)

@ktoso
Copy link
Member Author

ktoso commented Nov 3, 2016

Cool, thanks a lot Krzysztof :-)

@ktoso ktoso added 3 - in progress Someone is working on this ticket and removed 1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted labels Nov 3, 2016
KrzyMucha pushed a commit to KrzyMucha/akka-http that referenced this issue Nov 3, 2016
KrzyMucha pushed a commit to KrzyMucha/akka-http that referenced this issue Nov 3, 2016
jrudolph pushed a commit that referenced this issue Nov 3, 2016
)

Original RFC 2616 and newer RFC 6266 give different grammars / recommendations whether
to quote parameter values. It seems that current software is still confused about what to accept and what not.

Appendix A of RFC 6266 says:

      RFC 2616 only allows "quoted-string" for the filename parameter.
      This would be an exceptional parameter syntax, and also doesn't
      reflect actual use.

This doesn't mean that quotes are strictly required, so, given the reports of breakage
without quotes, let's force quotes for now for Content-Disposition parameters.
@jrudolph jrudolph added this to the 10.0.0 "first stable" milestone Nov 3, 2016
@jrudolph
Copy link
Member

jrudolph commented Nov 3, 2016

Fixed by #471.

@jrudolph jrudolph closed this as completed Nov 3, 2016
@ktoso ktoso modified the milestones: 10.0.0 "first stable", Final HTTP/2, 10.0.0-RC2 Nov 10, 2016
jedrekn pushed a commit to jedrekn/akka-http that referenced this issue Nov 17, 2016
akka#471)

Original RFC 2616 and newer RFC 6266 give different grammars / recommendations whether
to quote parameter values. It seems that current software is still confused about what to accept and what not.

Appendix A of RFC 6266 says:

      RFC 2616 only allows "quoted-string" for the filename parameter.
      This would be an exceptional parameter syntax, and also doesn't
      reflect actual use.

This doesn't mean that quotes are strictly required, so, given the reports of breakage
without quotes, let's force quotes for now for Content-Disposition parameters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - in progress Someone is working on this ticket discuss Tickets that need some discussion before proceeding t:core Issues related to the akka-http-core module
Projects
None yet
Development

No branches or pull requests

3 participants