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

URLFormEncoder does not escape all reserved characters #3173

Open
davedelong opened this issue Apr 15, 2024 · 3 comments
Open

URLFormEncoder does not escape all reserved characters #3173

davedelong opened this issue Apr 15, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@davedelong
Copy link

Describe the issue

URLFormEncoder should be encoding characters like $, but does not

Vapor version

4.92.5

Operating system and version

macOS 14.3

Swift version

5.9.0

Steps to reproduce

let form = ["hello": "world$"]
let encoder = try ContentConfiguration.global.requireEncoder(for: .urlEncodedForm)
var buffer = ByteBuffer()
var headers = HTTPHeaders()
try encoder.encode(form, to: &buffer, headers: &headers)

print(String(bytes: ByteBufferView(buffer), encoding: .utf8)!)

Outcome

This should print hello=world%24. Instead, it prints hello=world$.

Additional notes

According to Wikipedia, the reserved characters include $ and should be percent-escaped.

@davedelong davedelong added the bug Something isn't working label Apr 15, 2024
@davedelong davedelong changed the title URLFormEncoder does not escape reserved characters URLFormEncoder does not escape all reserved characters Apr 15, 2024
@davedelong
Copy link
Author

I believe that this CharacterSet is not excluding all the characters it should be.

@0xTim
Copy link
Member

0xTim commented Apr 26, 2024

Ok me and @gwynne did some diving into this and it's definitely a bug - I have no idea how it's been undiscovered this long. There doesn't appear to be a good actual RFC spec to refer to, but the best we've found is https://url.spec.whatwg.org/#application-x-www-form-urlencoded-percent-encode-set

The application/x-www-form-urlencoded percent-encode set contains all code points, except the ASCII alphanumeric, U+002A (*), U+002D (-), U+002E (.), and U+005F (_).

@0xTim
Copy link
Member

0xTim commented Apr 26, 2024

Will schedule a fix for this asap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants