-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
fix(http): don't expose body on GET/HEAD requests #12260
Conversation
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?).
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
GET/HEAD requests can't have bodies according to
fetch
spec. Thiscommit changes the HTTP server to hide request bodies for requests with
GET or HEAD methods.
Fixes #11927