fix(embed): use document.referrer origin for host_application#648
fix(embed): use document.referrer origin for host_application#648Kwame Yeboah (Yeboahmedia) wants to merge 5 commits into
Conversation
The host_application metadata field was always reporting the iframe's own host (cdn.smileidentity.com) because window.location inside the embed iframe is the CDN, not the partner site. Use document.referrer to capture the parent page origin instead, falling back to self-origin when referrer is empty (e.g. parent sets Referrer-Policy: no-referrer).
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
🔍 Semgrep Security Scan Results✅ No security findings detected by |
PR Code Suggestions ✨No code suggestions found for the PR. |
There was a problem hiding this comment.
Pull request overview
This PR fixes embed telemetry so host_application reflects the parent page’s origin (the site embedding the iframe) instead of always reporting the iframe/CDN origin.
Changes:
- Add a
getHostApplication()helper that deriveshost_applicationfromdocument.referrer(origin-only) with a fallback when referrer is unavailable. - Update
initializeMetadata()to use the new helper forhost_application. - Document the behavior change in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/embed/src/js/metadata/index.js | Switch host_application derivation from iframe location to referrer origin via a helper. |
| CHANGELOG.md | Add an Unreleased entry describing the host_application source change for embed. |
| if (document.referrer) { | ||
| try { | ||
| return new URL(document.referrer).origin; | ||
| } catch { | ||
| // fall through to self-origin fallback | ||
| } | ||
| } | ||
| return `${window.location.protocol}//${window.location.hostname}`; |
| export const initializeMetadata = async () => { | ||
| metadata = []; | ||
| const hostApplication = `${window.location.protocol}//${window.location.hostname}`; | ||
| addMetadataEntry('host_application', hostApplication); | ||
| addMetadataEntry('host_application', getHostApplication()); | ||
|
|
|
This branch has been deployed to s3 / cloudfront. ✅ Preview URL for Smart Camera Web: ✅ Preview URL for Embed: ✅ Preview URL for Web Client (Sandbox): ✅ Preview URL for Web Client (Production): |
Use window.location.origin for the fallback (matches the URL().origin format used in the referrer branch — includes port if non-default) and ignore the "null" serialization for opaque origins (about:blank, sandboxed iframes, data: URLs).
|
This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
|
Copilot resolve the merge conflicts in this pull request |
Merge conflicts are resolved in commit |
User description
Problem
The
host_applicationmetadata field always reportshttps://cdn.smileidentity.comfor hosted embed traffic, becausewindow.locationinside the iframe is the CDN host, not the partner site that loaded us.Fix
Use `document.referrer` (parsed via `URL` to keep just the origin) as the source for `host_application`, falling back to the iframe's own origin when the referrer is empty (parent set `Referrer-Policy: no-referrer`, privacy extensions, direct loads in dev).
Under the modern browser default (`strict-origin-when-cross-origin`), `document.referrer` already gives us the origin only — exactly what we want for this telemetry field — so partners don't need to change anything for this to start working.
Coverage expectation
Notes
PR Type
Bug fix
Description
Use
document.referrerorigin forhost_applicationmetadataFixes iframe always reporting CDN host instead of partner site
Falls back to self-origin when referrer is unavailable
Strips paths/queries via
new URL().originfor privacyDiagram Walkthrough
File Walkthrough
index.js
Derive host_application from document.referrer originpackages/embed/src/js/metadata/index.js
getHostApplication()helper function that readsdocument.referrerand extracts the originwindow.locationprotocol+hostname when referrer is emptyor URL parsing fails
hostApplicationassignment ininitializeMetadatawithcall to
getHostApplication()CHANGELOG.md
Add changelog entry for host_application fixCHANGELOG.md
host_applicationmetadata source change