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

MSC4138: Update allowed HTTP methods in CORS responses #4138

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions proposals/4138-update-cors-methods.md
Copy link
Member Author

Choose a reason for hiding this comment

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

Implementation requirements:

  • None, in my opinion. See "unstable prefix" section for rationale.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# MSC4138: Update allowed HTTP methods in CORS responses

The [specification](https://spec.matrix.org/v1.10/client-server-api/#web-browser-clients) suggests
that servers allow a limited subset of the available [HTTP methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)
available in [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) responses. However, it's
reasonable to expect the specification to use other methods in the future or as part of feature
detection. To permit these use cases early, this MSC proposes adding a few more allowable values to
the `Access-Control-Allow-Methods` header.

## Proposal

The [`Access-Control-Allow-Methods` header's recommended value](https://spec.matrix.org/v1.10/client-server-api/#web-browser-clients)
is updated to include the following:

* `PATCH` - A plausibly useful HTTP method for future use.
Copy link
Member

Choose a reason for hiding this comment

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

#4133 now wants to use this.

* `HEAD` - Similar to `PATCH`, `HEAD` is plausibly useful for feature detection and cases like
[MSC4120](https://github.com/matrix-org/matrix-spec-proposals/pull/4120).
turt2live marked this conversation as resolved.
Show resolved Hide resolved

The following methods are *not* included because they don't have foreseeable use in Matrix:

* `CONNECT`
* `TRACE`
Copy link
Member

Choose a reason for hiding this comment

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

I might suggest that this could be an MSC where we propose a literal update to the text of the spec: the current spec just plucks a recommendation out of thin air with no explanation of why it's recommended, but this MSC contains a bunch of useful context. I know you're trying to write it without including a reference to an in-review MSC in the spec, but I'm finding the result quite obtuse: "future use" just makes me wonder why the server wouldn't add those methods when it has an endpoint that actually uses them.

I would suggest something along the lines of, "if you implement all of the Matrix spec, you'll need this set, however this expanded set would be safe and sensible should you ever implement any MSCs that use them"?

Copy link
Member

Choose a reason for hiding this comment

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

or maybe something along the lines of "... if you implement any other endpoints that use other HTTP methods, make sure that you also include those methods on CORS".

Copy link
Member Author

Choose a reason for hiding this comment

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

#4138 (comment) is in line with this thread.

Will update the MSC.


## Potential issues

None anticipated.

## Alternatives

No significant alternatives.

## Security considerations

CORS is meant to help ensure requests made by the client are properly scoped in the client. If the
client wishes to use an HTTP method not allowed by the server, the web browser will mask the
response with an error before the application can inspect it. Therefore, to increase future
compatibility, we append a few useful HTTP methods while still excluding ones which are (currently)
nonsensical.

## Unstable prefix

This proposal cannot have an unstable prefix due to the nature of CORS. Servers are already able to
go off-spec and serve different headers because the spec is merely a recommendation.

## Dependencies

This proposal has no dependencies.