-
Notifications
You must be signed in to change notification settings - Fork 79
TrustedHTML.unwrap vs TrustedHTML.prototype.toString #35
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
Comments
Would I see that SafeTypes do:
What's the reason for the type marker? I believe we can make TT satisfy the instanceof checks and protect the inner value, e.g. with Symbols, but it'd be far to claim this is unforgeable. The threat model does not really include a malicious developer running the code in the execution context (they might be able to fool the type system in many ways, hooking into prototype functions of |
You're right, the threat model indeed assumes a non-malicious developer. However, we have found over the years that we do need to consider some notion of an "overly creative developer" that in order to get their work done might chose to write code that they really shouldn't and which (even though the individual piece of code looks correct to them) might weaken or invalidate whole-program correctness/assurance/reviewability properties (such as the ones we're after by using TrustedTypes). We've found that in practice, we should aim for a level of protection of the security invariants of these APIs where, to invalidate an invariant, a programmer would have to write code that should be quite clearly considered inappropriate by most developers in the org. For example, in Java code, it seems to be in practice reasonable to not have explicit mechanisms to defend against a developer using reflection to poke behind an API surface (and for instance, to implement their own equivalent of What level of defense against "creative circumvention of API intent" is necessary likely depends on the culture of organizations, and on the language. As a dynamic language without language-native field visibility, JS might require more active defenses. In the Closure types, we went with a horribly verbose field name, and the additional type marker (which TBH I'm not sure how much value it adds); combined with Closure compiler's static enforcement of I realize that there is only so much we can do. That said, the current implementation of the polyfill seems a bit too easy to get around; I wouldn't be all too surprised to see code like,
However, my guess is that we'd be in pretty solid shape if we could get to a point where in order to subvert the intent of the TrustedType system, a developer would have to muck with Re: the polyfill: I don't actually think it's necessary to strengthen the field-privacy defenses in the polyfill: As long as an application is tested or deployed to one browser that natively implements TrustedTypes (which presumably won't have the |
Implemented in the v2 API by using the |
It's unsound to accept a TrustedType as an input to a builder API without performing a runtime check.
E.g.,
is incorrect because there's no guarantee that run-time types of s1 and s2 are indeed TrustedHTML at a given call site (this is the case even if the code is compiled and statically type checked, since Closure as well as TypeScript type systems are unsound).
To address this concern, we made two design choices in the Closure SafeHtml types:
SafeHtml.unwrap
that performs a run-time type check of its argument.With that, the correct way to write a concat method is,
If we were to follow the capability/factory-based approach to controlling access to
unsafelyCreate
(proposed in #33 (comment)), it may make sense to provide the unwrap functions as part of the factory as well, to allow trusted-types builder code to be more confident that it's calling the genuine unwrap method.The text was updated successfully, but these errors were encountered: