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

Seeking Trusted Types feedback on Array.isTemplateObject #519

Open
littledan opened this issue May 28, 2024 · 5 comments
Open

Seeking Trusted Types feedback on Array.isTemplateObject #519

littledan opened this issue May 28, 2024 · 5 comments

Comments

@littledan
Copy link

littledan commented May 28, 2024

TC39 recently discussed Array.isTemplateObject, a feature to enable TT to allow literal HTML/JS strings. See the notes at https://github.com/tc39/notes/blob/main/meetings/2024-04/april-10.md#arrayistemplateobject-next-steps

The committee wanted to ask the Trusted Types experts: Do you have a preference for same-realm vs cross-realm brand checks? This question means: when you have multiple same-origin iframes, should Array.isTemplateObject guard against cross-realm template objects and return false for them?

My impression is that this question shouldn't matter for expected TT use cases, and either option should work. The normal case is that you apply the tag directly to the template, so you're not crossing template boundaries. The test we're doing is for literal-ness, not isolation context (ShadowRealms and cross-origin iframes are already isolated in different ways, which doesn't permit objects including templates to be shared at all).

My understanding is that the realm-specific query was difficult to implement in past attempts, but might be possible to do. The cross-realm check is simpler to specify and implement.

What would you prefer? Once I have an answer from this group, I'll bring it back to TC39 and propose it for Stage 2.7.

@lukewarlow
Copy link
Member

@koto you're probably best placed to answer this concretely.

My understanding is that for TT we don't care about realms. The threat model for TT is untrusted strings being used in "harmless" code. If someone manages to get to a realm with unprotected eval and fake mint a literal string well that's outside the threat model that TT protects against (relies on malicious code already executing on the page).

Cc @annevk too

@koto
Copy link
Member

koto commented May 28, 2024

That is correct, the realms don't matter much for the Trusted Types use case; to be more specific, if Array.isTemplateTag returns true for templates from another realm, it's fine for TT.

@annevk
Copy link
Member

annevk commented May 29, 2024

Reading the TC39 discussion the underlying assumption here is that template objects will never participate in serialize-deserialize? Is that enshrined somehow?

@littledan
Copy link
Author

@annevk This is a good point; what if this is enshrined with a note in both the Array.isTemplateObject description and the serialize-deserialize spec, which says "the template-object-ness is not currently serialized/deserialized; please consider TT implications if you ever do that"?

@annevk
Copy link
Member

annevk commented May 30, 2024

Currently it would become a plain Array, right? I think adding asserts in serialize-deserialize, possibly with a note, would suffice.

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

No branches or pull requests

4 participants