-
Notifications
You must be signed in to change notification settings - Fork 76
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
Allow for limiting the sinks that a type can be used for #152
Comments
No, this one is expected. In this particular policy we canonicalize the URL.
Correct.
Yes. We're leaving the implementation of the policies to the users (we are following up with somwe reference implementation & documentation of policies)
In this policy it's intentional, TOCTOU issue with the base URI is an issue, but rather this is done for clarity. It might be impractical to use absolute URLs everywhere in the document, but in that case the base URI TOCTOU is a security concern indeed, we should put it in an informational note or security considerations.
Thoughts, @otherdaniel @mikesamuel @xtofian? I personally would rather refrain from adding types for single sinks. Perhaps base uri can be mapped to
Yes (with the caveat that this is for script URLs, not URLs in general). We also discuss this in #151. This is the case in general - policies may transform their input, so write the policies in the way that doesn't break your application (unless if it only "breaks" unintentional behaviour like DOM XSS). |
Hmm...I don't understand what
|
Ah, I see the issue - that was a clear bug, I assumed the policy code returns the serialized parsed URL, fixed it in #153. |
Brian, does the commit address the issue? Would the appropriate resolution be to add a note to the spec that the relative / absolute URL mismatch may introduce a vulnerability via changing the base URI? The alternates are:
|
I think people will feel more comfortable adopting Trusted-Types if in I expect that most people who would use Trusted Types don't want I also think that Trusted Types works more like insecure blacklist-style sanitation. Inevitably, the number of sinks will increase over time. When you implement Similarly, the way the web APIs are annotated for Trusted Types seems too blacklist-y to me. Ideally, every web feature would be annotated with an indication of its Trusted Type, and any API not explicitly annotated would be assumed to be an XSS sink, for which no trusted type could be used, until such an annotation is added. |
Fair point, changed in 29ca732. Thanks!
Extracted to #172.
We plan to provide an authoritative information about the sinks that a given type will cover for a current document via #149, so the policy could reject creating a type if the mapping is too 'lax' for it. But what you propose is quite different indeed. Effectively, typed objects start being parametrized (each instance would become Authors can implement additional sink limitations with Trusted Types, e.g. by creating their own types wrapping TT and requiring them for some sinks (via sink setters replacement, or by banning the direct use of some setters, and requiring a specific function call), but I think there's value in making any instance of a given Trusted Type interchangeable (i.e. adhere to the same contract), as that's what's one of the core benefits of a type system.
I agree this would be ideal, but I don't think any user agent would be willing to implement a strongly typed version of each of the already existing, and all future web APIs. Just like That said, I feel confident that if the scope of the typed approach remains narrowly DOM XSS, it's possible for the spec bodies to keep up with the new script-related behavior of the web (just like for CSP). Correctly managing the mapping of types feels like it should be done in a spec, even if it starts as a blacklist; otherwise we'd have to rely on the authors to come up with the correct whitelist on their own (and there might some some interoperability problems down the road). |
This could be dealt with by having the policy registration pass in the sinks for which the policy is aware, instead of having |
That's true, however if multiple sinks are allowed by a policy, it might be practically hard to express that in a type language (I'm not sure this is actually the case here, calling @engelsdamien for TypeScript as an example - I'm also worried that it adds new API surface (e.g. I understand the risk of new sinks coming up, but I feel this should be dealt with at a spec level, by spec editors, and we should not add more work for the authors (in this case - to specify a whitelist of sinks), that has the side-effects that affects them. One idea on how to make this future-proof is #176. |
It is a little hard to tell how difficult it would be to express in typescript without first seeing what the api would look like. One thing in particular I did not understand in the proposal is how would the sinks be expressed, that is, what does an element of the That being said, I suspect this would end up being expressed as |
If I understand correctly, the use case would be for the authors to define a stricter rule set than what the current (post-TT) model is. For example limiting what can create a type for a given sink (say, By agreeing on some baseline enforcement on the DOM sinks (a collection of type => sinks relations) we are able to enforce some rules while staying interoperable. That is something that can be specced, implemented and maintained, but more importantly - used with little functional breakage risk. It sounds like the custom logic could be added in user code already, and a better place would be sinks, since it's them that trigger the enforcement. For example, like this: https://jsbin.com/gefoxaquda/edit |
Closing for the reasons mentioned earlier. We may revisit this for the next iterations of the API, but it seems like it increases the complexity of the design with little gain :/ |
The draft spec currently has this example:
First, is there a typo in this example? I am assuming it was intended to have
return parsed.toString();
instead ofreturn URL.toString();
.More to the point, if I understand the example correctly, this policy will replace any/all relative URI references and some non-normalized URI references with a different URI reference that is absolute and somewhat normalized. Also, it will (I think) reject some malformed strings. Questions:
Is the rejection of malformed strings here intentional? It would be good to document that users of TrustedTypes should generally some, but not all, malformed URI references to be rejected.
Is the conversion from a relative URI reference to absolute URI reference intetional? In particular, is the example trying to defend against a TOCTOU issue where
document.baseURI
changes between the time the TrustedScriptURL is constructed and the time it is used in the document? Are there other reasons one should do the relative-to-absolute conversion? I think any/all of these reasons we can come up with should be called out.In particular, the TOCTOU issue regarding
document.baseURI
and mitigations for it (e.g. using CSPbase-uri
) should be called out. Further, I think it would be useful to consider creating a specialTrustedBaseURL
and associated infrastructure (createBaseURL
, etc.) forHTMLBaseElement.href
to mitigate this, as most TrustedTypes users probably don'tdocument.baseURI
to change dynamically at all. I expect most implementations ofcreateURL
will fail to consider the possibility that the URL will be used for a<base>
element.Since the policy may transform the input URI reference to another URI reference, users of trusted types need to either lower their expectations about the form of the URI references in their document, or they need to make sure they use a policy that was designed to accommodate their expectations. For example, an application that assumes that all links in the document are relative URI references would need to be modified to stop making that assumption, or it would need to use a policy that accommodates this assumption. For example, here is a slight modification of the example policy that accommodates applications that make strong assumptions about the URI references they create:
The text was updated successfully, but these errors were encountered: