-
Notifications
You must be signed in to change notification settings - Fork 55
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
Wrap trusted-types policy creation in a try/catch #475
Conversation
Wrap policy-creation in try/catch
If |
@jeremymeng: It depends on whether the host application has If it's on: yes, the If it's off (or report-only), which is what our case was: |
Does "report-only" mean |
@jeremymeng , gentle ping. |
@Zlatkovsky sorry things move slower now that US is in the Thanksgiving holiday week. I will ping the Teams team again next week to get their Okay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
@Zlatkovsky v2.6.4 is now on npmjs. |
Original PR description: >Zlatkovsky commented on Nov 15, 2022 In our use-case of the ms-rest-js library, we have a large existing application (complete with caching, service-workers, etc) that we dynamically load additional JavaScript code into. The additional JS is what brings in the ms-rest-js. The application has Trusted Types enabled (e.g., CSP rule `'trusted-types LibraryA LibraryB etc`). But, interestingly, its `require-trusted-types-for 'script'` is currently under "report only" (`Content-Security-Policy-Report-Only`). In those cases, a call to `trustedTypes.createPolicy` will fail because the policy isn't on the allowed-list, even though _skipping_ the `createPolicy` would be OK. So in effect, Azure/ms-rest-js@531aea9 introduced a regression. We are working on extending the allow-list of our application to include `@azure/ms-rest-js#xml.browser`, but that change takes time. In the meantime, we'd like to wrap the policy-creation in a `try/catch`. There is no security risk to it, since for host applications that DO have strict enforcement of trusted-types, the code will simply fail when the dangerous sink is used (e.g., when doing `parseFromString`). And likewise, wrapping in `try/catch` and doing nothing on `catch` is OK, because the code already deals with the possibility of the trustedTypes API not being available on the browser.
Original PR description: >Zlatkovsky commented on Nov 15, 2022 In our use-case of the ms-rest-js library, we have a large existing application (complete with caching, service-workers, etc) that we dynamically load additional JavaScript code into. The additional JS is what brings in the ms-rest-js. > >The application has Trusted Types enabled (e.g., CSP rule `'trusted-types LibraryA LibraryB etc`). But, interestingly, its `require-trusted-types-for 'script'` is currently under "report only" (`Content-Security-Policy-Report-Only`). In those cases, a call to `trustedTypes.createPolicy` will fail because the policy isn't on the allowed-list, even though _skipping_ the `createPolicy` would be OK. So in effect, Azure/ms-rest-js@531aea9 introduced a regression. > >We are working on extending the allow-list of our application to include `@azure/ms-rest-js#xml.browser`, but that change takes time. In the meantime, we'd like to wrap the policy-creation in a `try/catch`. There is no security risk to it, since for host applications that DO have strict enforcement of trusted-types, the code will simply fail when the dangerous sink is used (e.g., when doing `parseFromString`). And likewise, wrapping in `try/catch` and doing nothing on `catch` is OK, because the code already deals with the possibility of the trustedTypes API not being available on the browser. ### Packages impacted by this PR `@azure/core-xml`
In our use-case of the ms-rest-js library, we have a large existing application (complete with caching, service-workers, etc) that we dynamically load additional JavaScript code into. The additional JS is what brings in the ms-rest-js.
The application has Trusted Types enabled (e.g., CSP rule
'trusted-types LibraryA LibraryB etc
). But, interestingly, itsrequire-trusted-types-for 'script'
is currently under "report only" (Content-Security-Policy-Report-Only
). In those cases, a call totrustedTypes.createPolicy
will fail because the policy isn't on the allowed-list, even though skipping thecreatePolicy
would be OK. So in effect, 531aea9 introduced a regression.We are working on extending the allow-list of our application to include
@azure/ms-rest-js#xml.browser
, but that change takes time. In the meantime, we'd like to wrap the policy-creation in atry/catch
. There is no security risk to it, since for host applications that DO have strict enforcement of trusted-types, the code will simply fail when the dangerous sink is used (e.g., when doingparseFromString
). And likewise, wrapping intry/catch
and doing nothing oncatch
is OK, because the code already deals with the possibility of the trustedTypes API not being available on the browser.