Repository navigation
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
Currently, if a custom protocol has corsEnabled: true, its resources are readable from any origin, and there's no way to restrict it so only certain origins can read from it. I propose that with this setting enabled, Electron should still check access-control-allow-origin headers so that the protocol can control which origins can read its responses.
Originally requested in #52498
My app has a custom protocol which I want to only be readable cross-origin only by certain origins. With the way this is implemented, it seems like it's impossible to do that. As the issue states, with enableCors: true, setting access-control-allow-origin or checking the origin header don't work, so the protocol is readable by every other origin. If it's set to false, the protocol isn't readable by any other origin.
IMO, requests on protocols with enableCors: true really should validate the access-control-allow-origin header. This is confusing enough that my AI agent wrote code assuming the header would be validated, and I only found out it didn't work that way after testing it. There's a minor note in the documentation about this now, but I think it should probably be a much more prominent warning if this behavior remains in place.
Proposed Solution
Electron should evaluate the access-control headers on a custom protocol response using the same logic that Chromium would use for a normal web response, and prevent cross-origin reads if not allowed by the header.
Alternatives Considered
Electron could pass the protocol a property with the requesting origin, so the handler could decide whether to return a response. This might be simpler to implement; however, supporting the access-control-* headers is a better fit for how things typically work on the web.
Additional Information
No response
Activity