-
Notifications
You must be signed in to change notification settings - Fork 15
Support Trusted Types from DOM lib #26
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
Thanks for reporting this. Due to internal issues, tsec can't accept external contributions (as stated in our CONTRIBUTING.md). I will patch this internally and release a new version. |
Could you provide some details about your setup? Did you swap out the original lib.dom.d.ts and use an updated one? Or is the updated lib.dom.d.ts released as an npm package? |
@uraj , do you have enough info to investigate this further? Any updates? Thanks. |
@tosmolka Sorry we're currently working on adding ESLint support. It should be done by the end of this week. After that I will add support for TT in DOM lib. Another thing that might be useful to know: in which file do you define the Trusted Types? Did you put the definition in lib.dom.d.ts or you have a separate file for Type declaration? |
@tosmolka I'm about to release a patch. Before that, want to confirm with you on how you amended lib.dom.d.ts. Did you just append something like below to the file? declare class TrustedHTML {
//...
} |
@uraj , I used this: 27256dc and applied patch using patch-package. |
Should be fixed by 1ceed96. Will publish a new version soon. |
Please try 0.2.4. |
@uraj , I did a quick test and I think this needs little bit of more work. I tried with HTMLScriptElement.src sink and tsec still flags when I do assignments with I think I faced similar issues when I proposed the PR and I fixed that by adding |
@tosmolka OK I got what you meant. I will discuss with the team and see whether we should support this form of assignments. With 0.2.4 you can now at least write
where |
@uraj , do you have any updates regarding support for this form of assignments? Thanks a lot. declare const trustedScriptUrl: string | TrustedScriptURL;
script.src = trustedScriptUrl; |
@tosmolka With lib.dom.d.ts patched, there is no longer the need to use declare const trustedScriptUrl: TrustedScriptURL;
script.src = trustedScriptUrl; Is that OK to you? |
I think we will continue using Now, if tsec keeps flagging this as an issue because But then I'd like tsec to be consistent and start flagging also this case: declare const trustedScriptUrl: string | TrustedScriptURL;
script.src = trustedScriptUrl as string; WDYT? |
We can flag that case, if we detect that |
…t of #26. PiperOrigin-RevId: 458421580 Change-Id: Ie5afc247632d77e4229cd401c95951700ba26871
@tosmolka I've submitted the patch, but for some reason I can't publish a new version right now. I will try over the weekends, but you can try out the patch before that if you want |
0.2.6 is now published. Let me know if the new version doesn't work for your setup. |
@uraj , I quickly checked the change. It seems to be working fine for intersection types - |
@tosmolka this is intended. I thought your project is OK with this, per our previous discussions. |
@uraj , I thought we were discussion union types - |
@tosmolka We were indeed talking about union types. The new behavior is that, if tsec found the definition of Trusted Types is ambient, union types like declare const trustedScriptUrl: string | TrustedScriptURL;
script.src = trustedScriptUrl as string; On unit tests: we do have them internally, but for some reason we don't export the test code to github. |
@uraj , OK, I misunderstood what is the intended behavior after your fix. Would be good to update docs accordingly at some point. Thanks. |
We are still waiting on DOM lib to fully support Trusted Types (microsoft/TypeScript#30024). I was proposing a fix in microsoft/TypeScript-DOM-lib-generator#1246 but it might take a while to get this merged in and released (= Safari or Firefox start supporting TTs).
I ran tsec against codebase that was using this updated DOM lib and found out that tsec does not recognize these built-in TT types.
For one, the matcher expects the types to be defined in DefinitelyTyped (@types/trusted-types):
tsec/src/third_party/tsetse/util/trusted_types_configuration.ts
Line 27 in a04e15a
It would be great if we could add this support to tsec for people (like us) who are already using DOM lib with TTs in their code.
The text was updated successfully, but these errors were encountered: