fix(security): add origin validation to postMessage handlers in embed SDK
β¦ SDK
What does this PR do?
Summary
Fixes #29371
Problems Fixed
embed.tsline ~408: postMessage was sending to"*"(any origin)embed.tsline ~1565: message listener had no origin validationembed-iframe.ts: same two issues on the iframe side
Changes
embed.ts: DerivetargetOriginfromiframe.srcinstead of using"*"embed.ts: Validatee.originagainstcalOriginconfig before processing messagesembed-iframe.ts: AddedgetParentOrigin()helper usingancestorOrigins[0]embed-iframe.ts: Validate incoming messages against expected parent origin
Security Impact
Prevents cross-origin message injection attacks on the Cal.com embed SDK.
- I haven't read the contributing guide
- My code doesn't follow the style guidelines of this project
- I haven't commented my code, particularly in hard-to-understand areas
- I haven't checked if my changes generate no new warnings
- My PR is too large (>500 lines or >10 files) and should be split into smaller PRs
Welcome to Cal.diy, @SahilArate! Thanks for opening this pull request.
A few things to keep in mind:
- This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy β they will not be deployed to the Cal.com production app.
- Please review our Contributing Guidelines if you haven't already.
- Make sure your PR title follows the Conventional Commits format.
A maintainer will review your PR soon. Thanks for contributing!
No actionable comments were generated in the recent review. π
βΉοΈ Recent review info
βοΈ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8feb4385-c47b-4f03-a755-3bbf19c17fe4
π₯ Commits
Reviewing files that changed from the base of the PR and between d24da16353d1274d52c5da9c2ec0e7e9201579a3 and daaed5bc9dee0b291f880a6b9770f3a23cc0a636.
π Files selected for processing (1)
packages/embeds/embed-core/src/embed-iframe.ts
π Walkthrough
Walkthrough
This PR hardens parentβiframe and global message origin validation, refactors embed UI/style setter registration and hooks, rewrites iframe URL construction and load logic (normalizing origin/path, query merging, and reload forcing), tightens connect/prerender flows and modal action decisions with explicit config equality checks, and applies merged UI CSS vars. It also adds "link-as-an-app" to the exported REDIRECT_APPS array.
π₯ Pre-merge checks | β 4 | β 1
β Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | β οΈ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
β Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | β Passed | The title clearly and specifically describes the main security fix: adding origin validation to postMessage handlers in the embed SDK. |
| Description check | β Passed | The description is related to the changeset, clearly detailing the security vulnerabilities fixed and the changes made across both embed.ts and embed-iframe.ts files. |
| Linked Issues check | β Passed | The PR comprehensively addresses all three objectives from issue #29371: adds e.origin validation to handlers in both embed.ts and embed-iframe.ts, and derives specific targetOrigin instead of using '*' for outbound postMessages. |
| Out of Scope Changes check | β Passed | All changes directly support the security fix objectives: refactors to embed-iframe.ts and embed.ts messaging/state logic are integrated with origin validation, and the redirect-apps addition appears unrelated but represents minimal scope creep. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
βοΈ Resolve merge conflicts
- [ ] Resolve merge conflict in branch
fix/postmessage-origin-validation
[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
π§ ESLint
If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add
eslintto devDependencies.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
This PR has been marked as stale due to inactivity. If you're still working on it or need any help, please let us know or update the PR to keep it active.
This PR has been marked as stale due to inactivity. If you're still working on it or need any help, please let us know or update the PR to keep it active.
This PR has been closed due to inactivity. Please feel free to reopen it if you'd like to continue the work.