question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Content Security Policy error in XML parsing in Chrome

See original GitHub issue

Describe the bug The Azure SDK for JavaScript includes a utility module for XML parsing. As part of initializing the module, it attempts to parse an invalid XML string at https://github.com/Azure/azure-sdk-for-js/blob/0f1c73f76331d23efb61c9f636ee2d2338b8e113/sdk/core/core-http/src/util/xml.browser.ts#L35 In most browsers, this returns a document containing a <parseerror> element describing the error. The error document contains inline styles which the browser interprets. In version 86.0 and newer of Chrome (https://bugs.chromium.org/p/chromium/issues/detail?id=1148221), the error document inherits the Content Security Policy from the owner document. Therefore, on pages with a Content Security Policy with a style-src directive not including unsafe-inline, Azure SDK for JavaScript causes a CSP error to be reported and shown in the console.

To Reproduce Steps to reproduce the behavior:

  1. Set up a page with a Content Security Policy with a style-src directive not containing unsafe-inline, for example style-src: 'self'.
  2. Load the Azure SDK for JavaScript.
  3. Open page in Google Chrome version 86.0 or newer.
  4. Look for Content Security Policy error in console.

Expected behavior No Content Security Policy error should be shown in the console.

Screenshots Content Security Policy error shown in console

Additional context I’m unsure if and when the issue in Chrome will be fixed. Until it is fixed, the XML parser module will necessarily cause a Content Security Policy error when parsing an invalid XML string on sites with the relevant policy. However, since XML parsing errors are likely not expected during normal usage of the library, it would still be beneficial to prevent the CSP error on load to save developer effort in debugging it.

Potential fixes could be to:

  1. Lazily testing for browser behavior when first parsing error is encountered, instead of at module load.
  2. Removing the check for browser behavior completely and always querying for the parsererror element, even in Internet Explorer.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremymengcommented, Feb 8, 2021

This has been published in @azure/core-http v1.2.3

1reaction
jeremymengcommented, Jan 25, 2021

One possibility could be to do a non-namespace-aware (getElementsByTagName) search for parserelement when parsing and then, if any are found, check each of their namespaces against a lazily computed (and potentially cached) error namespace.

Yes, this is exactly the same as I planned to do. Also thanks for the code snippets @kimsey0!

Read more comments on GitHub >

github_iconTop Results From Across the Web

XML parsing error for Content Security Policy - Stack Overflow
I'm having trouble getting the XML syntax correct for my blog's content security policy. It works when it's simple, but as soon as...
Read more >
Content security policy - web.dev
With this policy defined, the browser simply throws an error instead of loading script from any other source.
Read more >
Content Security Policy: Couldn't parse invalid source chrome ...
If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are...
Read more >
425118 - Security: Content Security Policy svg+xml - chromium
I just tested with 40.0.2188.2 (Official Build) dev using your PoC, and if I serve your provided sample policy under the Content-Security-Policy header,...
Read more >
Using Content Security Policy (CSP) to Secure Web Applications
Why Do We Need CSP? · History and Browser Support · Using CSP Directives · Source Whitelist Directives · Writing JavaScript and CSS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found