backport_1073409.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Thu, 4 Oct 2018 14:57:02 -0700
  4. Subject: fix: use parseHTMLSubset() in chrome://histograms.
  5. [1073409] [Low] [CVE-2020-6535]: XSS on chrome://histograms/ with a compromised renderer
  6. Backport https://chromium.googlesource.com/chromium/src/+/9a31a7ea51e0c7548f4ed77f5007e4a924ef0fbb
  7. diff --git a/content/browser/resources/histograms/BUILD.gn b/content/browser/resources/histograms/BUILD.gn
  8. index 9b67dcd52b2599855eb21b86b29a294094b22003..08c7f14373fa097bf540c60301d3802685affe0e 100644
  9. --- a/content/browser/resources/histograms/BUILD.gn
  10. +++ b/content/browser/resources/histograms/BUILD.gn
  11. @@ -13,6 +13,7 @@ js_type_check("closure_compile") {
  12. js_library("histograms_internals") {
  13. deps = [
  14. "//ui/webui/resources/js:cr",
  15. + "//ui/webui/resources/js:parse_html_subset",
  16. "//ui/webui/resources/js:util",
  17. ]
  18. }
  19. diff --git a/content/browser/resources/histograms/histograms_internals.html b/content/browser/resources/histograms/histograms_internals.html
  20. index 37e45404843d70bd2621fffc6f5f4e4e69786005..b997e6d2ff88f86c00bf4e4a099cd4999d66c061 100644
  21. --- a/content/browser/resources/histograms/histograms_internals.html
  22. +++ b/content/browser/resources/histograms/histograms_internals.html
  23. @@ -8,6 +8,7 @@
  24. <script src="chrome://resources/js/cr.js"></script>
  25. <script src="chrome://resources/js/promise_resolver.js"></script>
  26. <script src="chrome://resources/js/util.js"></script>
  27. + <script src="chrome://resources/js/parse_html_subset.js"></script>
  28. <script src="histograms_internals.js"></script>
  29. <title>Histograms</title>
  30. </head>
  31. diff --git a/content/browser/resources/histograms/histograms_internals.js b/content/browser/resources/histograms/histograms_internals.js
  32. index 24c55fb23c9f390a484572fe098e0cdcc79bc4ac..b70641ed43512391e4b75383b68196ba99590638 100644
  33. --- a/content/browser/resources/histograms/histograms_internals.js
  34. +++ b/content/browser/resources/histograms/histograms_internals.js
  35. @@ -24,9 +24,12 @@ function addHistograms(histograms) {
  36. htmlOutput += histogram;
  37. }
  38. - // NOTE: This is generally unsafe due to XSS attacks. Make sure |htmlOutput|
  39. - // cannot be modified by an external party.
  40. - $('histograms').innerHTML = htmlOutput;
  41. + // The following HTML tags are coming from
  42. + // |HistogramsMessageHandler::HandleRequestHistograms|.
  43. + const sanitizedHTML = parseHtmlSubset(`<span>${htmlOutput}</span>`, [
  44. + 'PRE', 'H4', 'BR', 'HR'
  45. + ]).firstChild.innerHTML;
  46. + $('histograms').innerHTML = sanitizedHTML;
  47. }
  48. /**