fix: validate origin and source on Klaviyo OAuth message handler [] - #11293
Merged
Michael Pineiro (michaelpineirocontentful) merged 3 commits intoSep 14, 2026
Conversation
Michael Pineiro (michaelpineirocontentful)
added this pull request to stack #11296
September 9, 2026 20:53
Michael Pineiro (michaelpineirocontentful)
force-pushed
the
fix/klaviyo-oauth-popup-target-origin
branch
from
September 11, 2026 15:08
ea019cc to
e488d5e
Compare
Michael Pineiro (michaelpineirocontentful)
force-pushed
the
fix/klaviyo-oauth-message-handler-origin-check
branch
from
September 11, 2026 15:08
bcd963b to
1000f1b
Compare
Michael Pineiro (michaelpineirocontentful)
marked this pull request as ready for review
September 11, 2026 15:09
Michael Pineiro (michaelpineirocontentful)
requested review from
a team
as code owners
September 11, 2026 15:09
david-shibley-contentful
previously approved these changes
Sep 11, 2026
david-shibley-contentful
left a comment
Contributor
There was a problem hiding this comment.
good call
ryunsong-contentful
previously approved these changes
Sep 11, 2026
Michael Pineiro (michaelpineirocontentful)
removed this pull request from stack #11296
September 14, 2026 14:09
Base automatically changed from
fix/klaviyo-oauth-popup-target-origin
to
master
September 14, 2026 14:09
Michael Pineiro (michaelpineirocontentful)
dismissed stale reviews from ryunsong-contentful and david-shibley-contentful
September 14, 2026 14:09
The base branch was changed.
…w messages The window message listener that completes the OAuth flow accepted any message posted to the window, regardless of where it came from or which window sent it. Reject messages that don't come from the app's own origin, or that don't come from the popup window this instance actually opened.
Michael Pineiro (michaelpineirocontentful)
force-pushed
the
fix/klaviyo-oauth-message-handler-origin-check
branch
from
September 14, 2026 14:09
1000f1b to
813a28c
Compare
#11294) * fix(klaviyo): scope OAuth popup message to the app's own origin The OAuth callback popup broadcast its completion message with a wildcard target origin, so any window that ended up as window.opener could receive the authorization code and state. Scope the postMessage call to the app's own origin instead of '*'. * fix(klaviyo): validate origin and source before acting on OAuth window messages The window message listener that completes the OAuth flow accepted any message posted to the window, regardless of where it came from or which window sent it. Reject messages that don't come from the app's own origin, or that don't come from the popup window this instance actually opened. * fix(klaviyo): anchor proxy endpoint allowlist to the full path shape The proxy's endpoint allowlist only checked the segment before the first slash, so a value like "template-universal-content/../lists" passed the check while the traversal segment let the request reach a Klaviyo endpoint that was never allowlisted. Replace the prefix check with a pattern anchored to the exact shape the app actually sends (an allowed endpoint, optionally followed by a single id segment), rejecting anything else outright. * test(klaviyo): add unit tests for the proxy endpoint allowlist Covers exact allowlist matches, an allowlisted endpoint plus a single id segment, and traversal attempts that previously bypassed the prefix-only check (verified these fail against the pre-fix code and pass against the anchored-pattern fix). Widen the vitest include glob to pick up functions/ tests — the functions/ directory previously had no test coverage at all. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * style(klaviyo): run prettier on the proxy allowlist test Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * refactor(klaviyo): drop the now-unused ALLOWED_ENDPOINTS array The allowlist check moved to ALLOWED_ENDPOINT_PATTERN; ALLOWED_ENDPOINTS only survived as an internal building block for that regex. Inline it directly into the pattern literal instead of keeping a separate binding nothing else reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
* fix(klaviyo): scope OAuth popup message to the app's own origin The OAuth callback popup broadcast its completion message with a wildcard target origin, so any window that ended up as window.opener could receive the authorization code and state. Scope the postMessage call to the app's own origin instead of '*'. * fix(klaviyo): validate origin and source before acting on OAuth window messages The window message listener that completes the OAuth flow accepted any message posted to the window, regardless of where it came from or which window sent it. Reject messages that don't come from the app's own origin, or that don't come from the popup window this instance actually opened. * fix(klaviyo): anchor proxy endpoint allowlist to the full path shape The proxy's endpoint allowlist only checked the segment before the first slash, so a value like "template-universal-content/../lists" passed the check while the traversal segment let the request reach a Klaviyo endpoint that was never allowlisted. Replace the prefix check with a pattern anchored to the exact shape the app actually sends (an allowed endpoint, optionally followed by a single id segment), rejecting anything else outright. * test(klaviyo): add unit tests for the proxy endpoint allowlist Covers exact allowlist matches, an allowlisted endpoint plus a single id segment, and traversal attempts that previously bypassed the prefix-only check (verified these fail against the pre-fix code and pass against the anchored-pattern fix). Widen the vitest include glob to pick up functions/ tests — the functions/ directory previously had no test coverage at all. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * style(klaviyo): run prettier on the proxy allowlist test Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * refactor(klaviyo): drop the now-unused ALLOWED_ENDPOINTS array The allowlist check moved to ALLOWED_ENDPOINT_PATTERN; ALLOWED_ENDPOINTS only survived as an internal building block for that regex. Inline it directly into the pattern literal instead of keeping a separate binding nothing else reads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * fix(klaviyo): stop writing the bearer token to function logs The Klaviyo request helper logged the full outgoing request headers (including the Authorization bearer token it had just set) whenever the API returned a non-OK response, and logged the raw token object on the invalid-token-format branch as well. Strip the Authorization header before logging request headers, and log only the token's type instead of the token value on the invalid-format error path. * test(klaviyo): add unit tests for token scrubbing in makeRequest Covers the two paths that previously leaked a secret to console.error: a non-OK API response (which logged the full request headers including Authorization) and an unrecognized token shape from the OAuth SDK (which logged the raw token object). Verified both fail against the pre-fix code and pass against the fix, and added a third test confirming the fix still logs enough to debug an API error (status, body, URL) without the secret. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * style(klaviyo): run prettier on the token-scrubbing test Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Michael Pineiro (michaelpineirocontentful)
enabled auto-merge (squash)
September 14, 2026 14:10
ryunsong-contentful
approved these changes
Sep 14, 2026
Michael Pineiro (michaelpineirocontentful)
merged commit Sep 14, 2026
299919a
into
master
15 checks passed
Michael Pineiro (michaelpineirocontentful)
deleted the
fix/klaviyo-oauth-message-handler-origin-check
branch
September 14, 2026 15:52
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.
Summary
The window message listener that completes the Klaviyo OAuth flow accepts any
messageevent delivered to the window, without checking where it came from or which window sent it. Combined with a same-origin sender, this closes the loop on validating the full message channel in both directions.Solution
Context
Stacked on top of the popup-side origin fix — this PR is the receiving half of the same channel. See that PR for the broader context on this stack.
Test plan
tsc --noEmitpassesvite build) succeeds