fix: stop writing the Klaviyo bearer token to function logs [] - #11295
Merged
Michael Pineiro (michaelpineirocontentful) merged 9 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-scrub-token-from-logs
branch
from
September 11, 2026 15:07
2ca5995 to
bd4c4e8
Compare
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 '*'.
…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.
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.
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>
Michael Pineiro (michaelpineirocontentful)
force-pushed
the
fix/klaviyo-proxy-endpoint-allowlist
branch
from
September 11, 2026 15:08
b97b7cb to
f4aefbc
Compare
Michael Pineiro (michaelpineirocontentful)
force-pushed
the
fix/klaviyo-scrub-token-from-logs
branch
from
September 11, 2026 15:08
bd4c4e8 to
a5e6beb
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
approved these changes
Sep 11, 2026
david-shibley-contentful
left a comment
Contributor
There was a problem hiding this comment.
oh gosh, this one 🤦
ryunsong-contentful
approved these changes
Sep 11, 2026
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Michael Pineiro (michaelpineirocontentful)
force-pushed
the
fix/klaviyo-scrub-token-from-logs
branch
from
September 11, 2026 15:49
a5e6beb to
16dc067
Compare
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>
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.
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>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Michael Pineiro (michaelpineirocontentful)
force-pushed
the
fix/klaviyo-scrub-token-from-logs
branch
from
September 11, 2026 16:16
16dc067 to
2b1ff57
Compare
david-shibley-contentful
approved these changes
Sep 11, 2026
Michael Pineiro (michaelpineirocontentful)
disabled auto-merge
September 11, 2026 20:46
ryunsong-contentful
approved these changes
Sep 11, 2026
Michael Pineiro (michaelpineirocontentful)
disabled auto-merge
September 14, 2026 14:08
Michael Pineiro (michaelpineirocontentful)
removed this pull request from stack #11296
September 14, 2026 14:09
Base automatically changed from
fix/klaviyo-proxy-endpoint-allowlist
to
fix/klaviyo-oauth-message-handler-origin-check
September 14, 2026 14:10
Michael Pineiro (michaelpineirocontentful)
merged commit Sep 14, 2026
c02abc2
into
fix/klaviyo-oauth-message-handler-origin-check
16 checks passed
Michael Pineiro (michaelpineirocontentful)
deleted the
fix/klaviyo-scrub-token-from-logs
branch
September 14, 2026 14:10
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 Klaviyo request helper logged the full outgoing request headers — including the
Authorizationbearer token it had just set — whenever the Klaviyo API returned a non-OK response. It also logged the raw token object on the invalid-token-format error path.Solution
Authorizationheader before logging request headers on API errors.Context
Last in a small stack of hardening fixes to the Klaviyo app found during a routine security review.
Test plan
tsc --noEmitpassesbuild-functions) succeeds