fix(app): use precise hostname match instead of substring for opencode.ai - #39480
Open
AuditAIH wants to merge 1 commit into
Open
fix(app): use precise hostname match instead of substring for opencode.ai#39480AuditAIH wants to merge 1 commit into
AuditAIH wants to merge 1 commit into
Conversation
…e.ai Replace String.includes() with a regex that only matches opencode.ai and *.opencode.ai. The previous substring match caused false positives on domains like opencode.aid.example.com, forcing the backend URL to localhost:4096 instead of location.origin. Fixes anomalyco#39479
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #39479
Type of change
What does this PR do?
The web frontend in
packages/app/src/entry.tsxusedString.includes()(substring match) to detect whether the page was served from an officialopencode.aidomain. This caused a false positive on any domain that merely contains the substringopencode.ai.When accessing the opencode web UI through a tunnel or reverse proxy using a domain like
opencode.aid.example.com, the checklocation.hostname.includes("opencode.ai")returnedtrue, so the frontend forced the backend URL tohttp://localhost:4096instead oflocation.origin. Sincelocalhostrefers to the remote browser's own machine (not the server behind the tunnel), all API requests failed.The fix replaces the substring match with a regex that precisely matches
opencode.aiand*.opencode.ai:This is consistent with the CORS side (
packages/server/src/cors.ts), which already uses a precise regex:includes)opencode.aiapp.opencode.aia.b.opencode.aiopencode.aid.example.commyopencode.aiHow did you verify your code works?
Tested with a tunnel proxy using a domain containing the
opencode.aisubstring. Before the fix, the frontend connected tolocalhost:4096and all API requests failed. After the fix, the frontend correctly useslocation.origin(the tunnel domain) as the backend URL.Screenshots / recordings
Checklist