fix(backend): restrict CORS to configurable origins and explicit methods/headers#1283
fix(backend): restrict CORS to configurable origins and explicit methods/headers#1283dataCenter430 wants to merge 1 commit intoeigent-ai:mainfrom
Conversation
|
thanks @dataCenter430 for the PR, could @4pmtong and @nitpicker55555 help reviewing this? |
There was a problem hiding this comment.
@Wendong-Fan @dataCenter430 @4pmtong I think this pr is redundent, eigent is desktop application, if the backend only binds to localhost, CORS restrictions provide no real security value for local APIs; hardcoding headers is also fragile.
Suggest to close
|
Thanks for the feedback. @nitpicker55555 If we’re confident the backend will never be used outside the current model, I’m okay but I wanted to add a minimal safety net for likely future scenarios. |
"defense-in-depth" argument doesn't apply here — defense-in-depth requires an actual threat surface, and a localhost-only API has none. Future-proofing for hypothetical scenarios (containerization, external exposure) is YAGNI — if the architecture changes, CORS requirements will be different anyway, and can be added at that point with the real constraints in mind. Best practice is matching security measures to the actual threat model, not applying web patterns to desktop apps. Suggest to close. |
|
Thanks for the thoughtful feedback, I agree that security controls should match the actual threat model, and that a localhost-only API does not present a traditional remote attack surface. |
Electron’s renderer accesses the backend via The “problem” you’re trying to solve — restricting which origins can access the backend — does not present a realistically exploitable attack surface in a desktop application context. |
Related Issue
CORS configuration: missing or overly permissive CORS can allow unwanted origins.
Closes #1260
Description
Replace permissive CORS (allow_origins=[""] with allow_credentials=True and
allow_methods/allow_headers=[""]) with a safe, configurable setup:
In development, if unset, allow only http://localhost:5173, 127.0.0.1:5173,
and ports 3000. In non-development, allow no origins until CORS_ORIGINS is set.
Document CORS_ORIGINS in backend README. Ensures credentials work correctly
(no wildcard origin with credentials) and reduces risk of unwanted origins
calling the API from the browser.
Why?
What is the purpose of this pull request?
Contribution Guidelines Acknowledgement