Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The critical origin mismatch can reject all messages when Referer is absent.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes webchat message rejection after rerenders by preserving the client-resolved embedding origin.
Changes:
- Stabilizes the origin for message submissions and menu actions.
- Adds regression coverage across rerenders and form resets.
File summaries
| File | Summary |
|---|---|
apps/builder/src/features/integration-webchat/webchat-message-input.tsx |
Preserves the embedding origin. Critical (1 vote): a null server origin can mismatch token minting when Referer is absent. |
apps/builder/__tests__/webchat-message-input-origin.test.tsx |
Tests origin persistence. Nit (1 vote): the mock does not derive the second request from reset state. |
Review details
Suppressed comments (1)
apps/builder/tests/webchat-message-input-origin.test.tsx:38
- This mock submitter builds every request from
mocks.defaultValues, which is overwritten on each render, whileform.resetis only a no-op spy. Consequently the second submit never reads the form state produced byreset(defaultValues), so a regression in the reset path could still pass this test. Track the mock form values (and update them fromreset) or assert the reset argument and derive the second request from that state.
const submit = async () => {
const input = {
...mocks.defaultValues,
text: "hello",
}
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+47
to
+50
| useEffect(() => { | ||
| const clientEmbeddingOrigin = getClientEmbeddingOrigin() | ||
| if (clientEmbeddingOrigin) { | ||
| setEmbeddingOrigin(clientEmbeddingOrigin) |
Author
|
Addressed in the latest commit. Null server origins now remain null, and the regression test now tracks reset form state. |
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.
What
Embedded webchat text messages could start sending the iframe's own origin after a rerender instead of the embedding site's origin.
Subsequent messages were then rejected with:
This website is not authorized to load this chat widget.Root cause
WebchatMessageInputused the server-derivedparentOriginin its form defaults. After a rerender with the iframe origin,reset(defaultValues)could replace the original embedding-site origin, causing later submissions to mismatch the access token'soriginHost.Fix
getClientEmbeddingOrigin()Authorization and authorized-domain validation remain unchanged.
Tests
Added a regression test covering:
parent origin → rerender with iframe origin → first submit → reset → second submitBoth submissions retain the original embedding-site origin.
git diff --checkpasses. The focused Vitest test could not run locally because of a WindowsEPERMenvironment issue; CI should validate it.Fixes #1166