New option to enforce CORS in HTTP and WS transport plugins #2410
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As the title says, this PR adds a new option to both the HTTP and WebSocket transport plugins to actually enforce CORS. In fact, it's up to browsers to enforce CORS once the relevant headers have been exchanged, and in case of WebSockets that actually never happens anyway. This PR allows you to enforce it on the server side too, if you want: by returning a
403
in the HTTP plugin, and just closing the connection attempt in the WS plugin.I haven't tested this much, so I'd appreciate some feedback on whether or not the way I'm dealing with this works. For instance, GET messages are known to rarely include an
Origin
header, which is why in the HTTP plugin I'm relying on theReferer
header instead; besides, I only played a bit with Chrome, but not other browsers, so there may be other things that need fixing before this can be merged.