Skip to content

Do not abort cross-origin requests with an empty 200 (#1955)#1975

Open
svpernova09 wants to merge 1 commit into
php:masterfrom
svpernova09:prevent-returning-blank-responses
Open

Do not abort cross-origin requests with an empty 200 (#1955)#1975
svpernova09 wants to merge 1 commit into
php:masterfrom
svpernova09:prevent-returning-blank-responses

Conversation

@svpernova09

Copy link
Copy Markdown
Contributor

How to reproduce

$ tests/server start
$ git checkout master

$ curl -s -o /dev/null -w '%{http_code} %{size_download}\n' \
-H 'Origin: https://example.com' http://localhost:8080/
200 0

$ curl -s -o /dev/null -w '%{http_code} %{size_download}\n' \
http://localhost:8080/
200 53385

Same URL, same server. One request-header a client fully controls turns the page into a zero-byte 200 OK.

exit(10) at include/prepend.inc:31 sets a process exit status and emits no body, so the response is a perfectly
valid success with nothing in it.

That empty body then gets cached and served to everyone: Origin is not part of the CDN cache key and we send no Vary
header. It also persists, because Cache-Control: public, max-age=300 is set later in include/header.inc:54 and never
runs, so the CDN applies its own default TTL instead of five minutes.

On this branch:

$ git checkout prevent-returning-blank-responses

$ curl -s -o /dev/null -w '%{http_code} %{size_download}\n' \
-H 'Origin: https://example.com' http://localhost:8080/
200 53385

Comment thread include/prepend.inc
if (!$isTrustedOrigin) {
// Serve the page normally, only without any CORS headers.
if (in_array($_SERVER["REQUEST_METHOD"] ?? "GET", ["GET", "HEAD", "OPTIONS"], true)) {
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand why you're allowing these three methods without the CORS origin server to match.

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.

2 participants