backport_1074317.patch 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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: stop leaking cross-origin post-redirect data using StackTrace
  5. [1074317] [High] [CVE-2020-6511]: Security: The CSP reports and stacktraces of errors leaks post-redirect URL for <script>
  6. Backport https://chromium.googlesource.com/chromium/src/+/0b707cbaa2cb806162797be55caf9f8074fbdccf
  7. diff --git a/third_party/blink/renderer/bindings/core/v8/script_source_code.cc b/third_party/blink/renderer/bindings/core/v8/script_source_code.cc
  8. index 2993ffb7c084406ed731744e6c854d0ece5d207b..4bc73561d781713355bd94631914a1f2305e0c2f 100644
  9. --- a/third_party/blink/renderer/bindings/core/v8/script_source_code.cc
  10. +++ b/third_party/blink/renderer/bindings/core/v8/script_source_code.cc
  11. @@ -4,6 +4,7 @@
  12. #include "third_party/blink/renderer/bindings/core/v8/script_source_code.h"
  13. +#include "base/feature_list.h"
  14. #include "third_party/blink/renderer/core/loader/resource/script_resource.h"
  15. namespace blink {
  16. @@ -46,8 +47,16 @@ String SourceMapUrlFromResponse(const ResourceResponse& response) {
  17. return response.HttpHeaderField(http_names::kXSourceMap);
  18. }
  19. +const base::Feature kUnsafeScriptReportPostRedirectURL{
  20. + "UnsafeScriptReportPostRedirectURL", base::FEATURE_DISABLED_BY_DEFAULT};
  21. +
  22. } // namespace
  23. +// static
  24. +bool ScriptSourceCode::UsePostRedirectURL() {
  25. + return base::FeatureList::IsEnabled(kUnsafeScriptReportPostRedirectURL);
  26. +}
  27. +
  28. ScriptSourceCode::ScriptSourceCode(
  29. const ParkableString& source,
  30. ScriptSourceLocationType source_location_type,
  31. @@ -83,8 +92,9 @@ ScriptSourceCode::ScriptSourceCode(ScriptStreamer* streamer,
  32. cache_handler_(resource->CacheHandler()),
  33. streamer_(streamer),
  34. not_streaming_reason_(reason),
  35. - url_(
  36. - StripFragmentIdentifier(resource->GetResponse().CurrentRequestUrl())),
  37. + url_(StripFragmentIdentifier(
  38. + UsePostRedirectURL() ? resource->GetResponse().CurrentRequestUrl()
  39. + : resource->Url())),
  40. source_map_url_(SourceMapUrlFromResponse(resource->GetResponse())),
  41. start_position_(TextPosition::MinimumPosition()),
  42. source_location_type_(ScriptSourceLocationType::kExternalFile) {
  43. diff --git a/third_party/blink/renderer/bindings/core/v8/script_source_code.h b/third_party/blink/renderer/bindings/core/v8/script_source_code.h
  44. index 8fe2bd4e487ff6a67cbe6a3cfb9e00bd5a85da32..41023cec3603a67dba15b71c4b2e3ba12f222f8a 100644
  45. --- a/third_party/blink/renderer/bindings/core/v8/script_source_code.h
  46. +++ b/third_party/blink/renderer/bindings/core/v8/script_source_code.h
  47. @@ -49,6 +49,20 @@ class CORE_EXPORT ScriptSourceCode final {
  48. DISALLOW_NEW();
  49. public:
  50. + // Return whether chrome should use the request URL or the response URL as the
  51. + // 'url' of the script. This can be observed in:
  52. + // 1) The 'source-file' in CSP violations reports.
  53. + // 2) The URL(s) in javascript stack traces.
  54. + // 3) How relative source map are resolved.
  55. + //
  56. + // This returns false by default. This corresponds to the current
  57. + // specification and matches Firefox behavior. This also avoids leaking
  58. + // post-redirect data cross-origin. See https://crbug.com/1074317.
  59. + //
  60. + // This can be enabled using the switch:
  61. + // --enable-features=UnsafeScriptReportPostRedirectURL
  62. + static bool UsePostRedirectURL();
  63. +
  64. // For inline scripts.
  65. ScriptSourceCode(
  66. const String& source,
  67. diff --git a/third_party/blink/renderer/core/workers/worker_global_scope.cc b/third_party/blink/renderer/core/workers/worker_global_scope.cc
  68. index 10f2de79d8eab681607f3b748cdf823386351cf2..12d6d90ea2ea6178fc9e83df5430fe5df80d4d73 100644
  69. --- a/third_party/blink/renderer/core/workers/worker_global_scope.cc
  70. +++ b/third_party/blink/renderer/core/workers/worker_global_scope.cc
  71. @@ -265,7 +265,9 @@ void WorkerGlobalScope::ImportScriptsInternal(const Vector<String>& urls,
  72. source_code.length(), handler ? handler->GetCodeCacheSize() : 0);
  73. ScriptController()->Evaluate(
  74. ScriptSourceCode(source_code, ScriptSourceLocationType::kUnknown,
  75. - handler, response_url),
  76. + handler,
  77. + ScriptSourceCode::UsePostRedirectURL() ? response_url
  78. + : complete_url),
  79. sanitize_script_errors, &error_event, GetV8CacheOptions());
  80. if (error_event) {
  81. ScriptController()->RethrowExceptionFromImportedScript(error_event,