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

Update overlay.ts to support CSP require-trusted-types-for #15850

Closed
4 tasks done
Snugug opened this issue Feb 8, 2024 · 3 comments · Fixed by #15852
Closed
4 tasks done

Update overlay.ts to support CSP require-trusted-types-for #15850

Snugug opened this issue Feb 8, 2024 · 3 comments · Fixed by #15852

Comments

@Snugug
Copy link
Contributor

Snugug commented Feb 8, 2024

Description

Similar to #15686, overlay.ts uses innerHTML (

this.root.innerHTML = template
) to display error messages. innerHTML isn't compatible with require-trusted-types-for, so this fails.

Suggested solution

I think the easiest solution here is turning the template (

const template = /*html*/ `
) into a Trusted Type policy (MDN example) if TTs are defined, and leaving it as a string otherwise. This would also require updating the innerHTML call for the template if TTs are available, too.

Alternative

The other alternative is converting this to DOM creation calls and appending it to the DOM, but per my proposed solution to #15686, I'm assuming that's not a likely solution that y'all are interested in adopting.

Additional context

This can be tested now by following my steps in #15686 (comment) and forcing Vite to throw an error.

I did a quick search of the codebase and this was the only core file that I found that used innerHTML, but it's possible there are other cases where this would throw for the CSP that I'm not otherwise aware of. I'd also recommend adding into the Vite coding style guide to avoid innerHTML in core code shipped to browsers.

Validations

@Snugug
Copy link
Contributor Author

Snugug commented Feb 8, 2024

I'm also happy to write the Trusted Types conversion for this as I've got an environment set up to test this on already, but am going to hold off doing so until maintainers give me a +1 to do so

@patak-dev
Copy link
Member

I agree with you here. This is for internal code so we should be fine here. It is different than with the template. At the risk of making you do work again that we don't end up merging, I think the best is to send the PR so we can discuss with the change in the table.

@Snugug
Copy link
Contributor Author

Snugug commented Feb 8, 2024

Will do, and no problem writing more code! Would you prefer the Trusted Types solution or the DOM method solution?

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants