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

fix: set innerText instead of innerHTML #264

Merged
merged 3 commits into from
May 8, 2024

Conversation

bsmth
Copy link
Member

@bsmth bsmth commented Feb 29, 2024

Setting innerHTML from an iframe allows unsafe contents in the main page. Switching to innerText instead.

Also adding some styles so it's apparent what is the iframe in the index.html

Compat:

I've noticed this breaks in Fx, but works in Chrome and Safari. It could be down to stricter handling of targetOrigins (* in this case) see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns

@bsmth bsmth requested a review from a team as a code owner February 29, 2024 10:44
@bsmth bsmth requested review from pepelsbey and removed request for a team February 29, 2024 10:44
@pepelsbey
Copy link
Member

Regarding the compat: it works in Firefox via a local server, but doesn’t when opened as a file.

image

@pepelsbey
Copy link
Member

I also noticed that the original demo works only in Safari but not in Chrome or Firefox: see [object Object] in the frame.

image

@bsmth
Copy link
Member Author

bsmth commented Feb 29, 2024

Regarding the compat: it works in Firefox via a local server, but doesn’t when opened as a file.

Really? I was serving it also, so I wonder if it's to do with that. I'm using http-server:

http-server -c-1
http-server --v
# v14.1.1

I'll try some other options

@bsmth
Copy link
Member Author

bsmth commented Mar 4, 2024

I re-tested and I realized it's from Fx nightly that I get compat issues, it could be a pref I've changed, I'm not sure.

Anyway, this works as expected in

  • Fx 122.0.1 (64-bit) & 123.0 (64-bit) after update
  • Safari Version 17.2.1 (19617.1.17.11.12)
  • Chrome Version 122.0.6261.94 (Official Build) (arm64)

Tested using both of these:

cd channel-messaging-basic
http-server -c-1
# ^C
python3 -m http.server

I also noticed that the original demo works only in Safari but not in Chrome or Firefox: see [object Object] in the frame.

I don't see this using the browser versions listed above, could you check again? I did get [object Object] in Fx nightly but only on localhost

@bsmth
Copy link
Member Author

bsmth commented Mar 19, 2024

btw @pepelsbey, this is ready for another look when you have time. No rush 🙌🏻

Copy link
Member

@pepelsbey pepelsbey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I got distracted by the compatibility. It has been like that before this PR, so it’s irrelevant here. LGTM!

@pepelsbey pepelsbey merged commit 36eba9f into mdn:main May 8, 2024
3 checks passed
@bsmth bsmth deleted the sanitize-MessageChannel-input branch May 10, 2024 08:28
@bsmth
Copy link
Member Author

bsmth commented May 10, 2024

Thank you!

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.

2 participants