cal.diy icon indicating copy to clipboard operation
cal.diy copied to clipboard

fix(security): add origin validation to postMessage handlers in embed SDK

Open SahilArate opened this issue 6 months ago β€’ 4 comments

… SDK

What does this PR do?

Summary

Fixes #29371

Problems Fixed

  • embed.ts line ~408: postMessage was sending to "*" (any origin)
  • embed.ts line ~1565: message listener had no origin validation
  • embed-iframe.ts: same two issues on the iframe side

Changes

  • embed.ts: Derive targetOrigin from iframe.src instead of using "*"
  • embed.ts: Validate e.origin against calOrigin config before processing messages
  • embed-iframe.ts: Added getParentOrigin() helper using ancestorOrigins[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

SahilArate avatar May 23 '26 10:05 SahilArate

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!

github-actions[bot] avatar May 23 '26 10:05 github-actions[bot]

Review Change Stack

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 eslint to 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.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 23 '26 10:05 coderabbitai[bot]

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.

github-actions[bot] avatar Jun 08 '26 01:06 github-actions[bot]

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.

github-actions[bot] avatar Jun 16 '26 01:06 github-actions[bot]

This PR has been closed due to inactivity. Please feel free to reopen it if you'd like to continue the work.

github-actions[bot] avatar Jul 01 '26 01:07 github-actions[bot]