fix: filter CORS headers in response to prevent duplicate header conf…#38
Open
gogui63 wants to merge 1 commit intokoush:mainfrom
Open
fix: filter CORS headers in response to prevent duplicate header conf…#38gogui63 wants to merge 1 commit intokoush:mainfrom
gogui63 wants to merge 1 commit intokoush:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When accessing Scrypted through Home Assistant's ingress proxy behind a
reverse proxy (e.g., nginx), CORS headers from Scrypted were being passed
through to the client. This caused conflicts with CORS headers added by
Home Assistant itself, resulting in an AssertionError:
This occurred because aiohttp's CORS middleware detected duplicate
Access-Control-Allow-Credentials headers.
Changes:
_response_header()to filter out CORS-related headers fromScrypted's responses (Access-Control-Allow-Origin, Allow-Credentials,
Allow-Methods, Allow-Headers, Expose-Headers, Max-Age)
retrieve_token()to support both the legacy API responseformat (token field) and the newer format (authorization field with
Bearer prefix)
This fix enables Scrypted integration to work correctly when Home Assistant
is accessed through an external reverse proxy with HTTPS.
Tested configuration:
Problem
Users accessing Home Assistant remotely through a reverse proxy (nginx,
Traefik, Caddy, etc.) were unable to use the Scrypted integration. The
panel would fail to load with a cryptic CORS error in Home Assistant logs.
This is a common setup for users who want secure external access to their
Home Assistant instance without exposing it directly to the internet.
Root Cause
headers unchanged
Additionally, the Scrypted API has evolved and now returns authentication
tokens in a different format (
authorization: Bearer xxxinstead oftoken: xxx), which caused login failures in some configurations.Solution
Filter out all CORS-related headers from Scrypted's responses before
forwarding them to the client, letting Home Assistant handle CORS
consistently. Also added backward-compatible token parsing to support
both old and new Scrypted API responses.