Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only receives window messages from the parent window (aka this.source) #284

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

real2two
Copy link

@real2two real2two commented Nov 18, 2024

Added a check to see if the event source (event.source) is the source/parent (this.source`) frame. This prevents DiscordSDK from picking from window messages from child iframes (iframes within the activity iframe).

If you were to run this code snippet within an iframe in a Discord activity's iframe, DiscordSDK would pick it up on the handleMessage function:

(window.parent.opener ?? window.parent).postMessage("custom value", "*");

The result of executing the following script above in a (sandboxed) iframe within the activity iframe:

image

This is something you wouldn't want to allow if you're displaying arbitrary iframes with user-generated content in your Discord activity, so I added a if (event.source !== this.source) return; under this code segement:

private handleMessage = (event: MessageEvent) => {
if (!ALLOWED_ORIGINS.has(event.origin)) return;

I haven't fully tested this change and don't know if there's any unintended side-effects of it, but this change seems to be working for me currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant