Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cute-apes-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

fix(clerk-js): update inCrossOriginIframe to handle nested cross origin iframes
18 changes: 15 additions & 3 deletions packages/clerk-js/src/utils/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ export function inIframe() {
}

export function inCrossOriginIframe() {
// https://developer.mozilla.org/en-US/docs/Web/API/Window/frameElement
// frameElement: if the document into which it's embedded has a different origin, the value is null instead.
return inIframe() && !window.frameElement;
if (!inIframe()) {
return false;
}

try {
// Try to access top window's location to check if any ancestor is cross-origin
// This will throw a SecurityError if any iframe in the chain is cross-origin
// Handles nested iframes where immediate parent might be same-origin
// but a higher-level ancestor is cross-origin
void window.top?.location.href;
return false;
} catch {
// SecurityError thrown - we're in a cross-origin iframe (at any level)
return true;
}
}
Loading