feat: support allowedOrigin option#21
feat: support allowedOrigin option#21DriesOlbrechts wants to merge 6 commits intoprismicio:masterfrom
Conversation
…usted origins from sending requests to the simulator
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
|
Hi @DriesOlbrechts, thank you so much for opening this PR! I'm trying to carve time to move forward with it, as I think there could be a way to allow messages from Prismic domains by default, which would make it secure by default for everyone :) If this is of any pressing matter to you let me know! |
|
Hi @lihbr , That would be even better! Thanks for looking at this! |
|
OK, I tried a few things and came up with #24 The approach is similar to yours, but transparent for users:
I didn't add the origin enforcement on messages sent by the receiver (i.e. Slice Simulator page):
Let me know if that compromise is acceptable to you~ I also credited you as a co-author on my commit, so your contribution is not lost! |
|
That all makes sense to me. It still removes the potential vulnerability! Thank you! |
|
Awesome, released #24 as |

Description
Currently the slice simulator accepts postMessage requests from any origin, this is not a direct issue, but when slices are made that do not sanitize for example html input. This can be abused to access the websites domain.
While this issue isn't on Prismic's side, adding this option, and strongly advocating for it's use in the documentation can prevent these attacks from being possible even when there are unsafe components.
This should still be implemented in the SliceSimulator component as well so developers can set the correct origin for their prismic dashboard.
I hope the issue is clear, let me know if not!
Checklist
Note
Medium Risk
Touches cross-window messaging behavior by adding optional origin filtering and targetOrigin restriction; misconfiguration could break iframe communication, but default keeps existing behavior.
Overview
Adds an optional
allowedOrigin(defaultnull) toChannelReceiver/SimulatorAPIto restrict postMessage communication to a single trusted origin.When set, inbound
messageevents from other origins are ignored,ready()posts to the configuredtargetOrigininstead of*, andConnectrequests can no longer overrideallowedOrigin.SimulatorManagernow accepts/passes throughallowedOrigin, with new tests covering defaults and origin enforcement.Reviewed by Cursor Bugbot for commit 509585b. Bugbot is set up for automated code reviews on this repo. Configure here.