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

fix(http): don't expose body on GET/HEAD requests #12260

Merged
merged 3 commits into from
Oct 11, 2021

Conversation

lucacasonato
Copy link
Member

GET/HEAD requests can't have bodies according to fetch spec. This
commit changes the HTTP server to hide request bodies for requests with
GET or HEAD methods.

Fixes #11927

GET/HEAD requests can't have bodies according to `fetch` spec. This
commit changes the HTTP server to hide request bodies for requests with
GET or HEAD methods.
@@ -95,7 +95,12 @@
let body = null;
if (typeof requestRid === "number") {
SetPrototypeAdd(this.managedResources, requestRid);
body = createRequestBodyStream(this, requestRid);
// There might be a body, but we don't expose it for GET/HEAD requests.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to refer to the relevant portion(s) of the spec here?

Copy link
Member Author

@lucacasonato lucacasonato Sep 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the Request creation that is internal to our HTTP server, so there is no spec. The new Request constructor that is exposed to users enforces this in step 34 of the constructor steps: https://fetch.spec.whatwg.org/#dom-request

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the Request creation that is internal to our HTTP server, so there is no spec.

Then why do we have to hide bodies on incoming requests?
And if we do, what about other methods that can't have bodies - OPTIONS and TRACE (DELETE?).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because users can not do new Request(incomingReq) (this throws) for an unmodified incoming GET request from the HTTP server. See #11927. We are creating an invalid Request instance because we are creating it internally, bypassing the usual request constructor checks. There is no possibility on the web platform to create a Request object where method === "GET" && body !== null. Because of this we should not have one either.

OPTIONS, TRACE, and DELETE requests can have bodies in fetch on the web platform. GET and HEAD can not.

Copy link
Contributor

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no opinion on what the fetch() spec says but HTTP in general allows GET requests with bodies.

Not that they're very useful - the server isn't allowed to attach semantic meaning to them, what with GET being idempotent - but it's a thing.

ext/http/lib.rs Outdated Show resolved Hide resolved
@lucacasonato lucacasonato merged commit c40d504 into denoland:main Oct 11, 2021
@lucacasonato lucacasonato deleted the no_body_for_get_head branch October 11, 2021 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new Request(request) throws with hyper + http/2
4 participants