cherry-pick-dd8e2822e507.patch 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Patrick Meenan <[email protected]>
  3. Date: Thu, 6 Feb 2025 07:41:40 -0800
  4. Subject: Set is_web_secure_context when initializing Service Worker from disk
  5. The value of is_web_secure_context is not serialized to disk when
  6. storing the service worker registration (only a few select policies
  7. are).
  8. When instantiating the policy container for an already-registered
  9. worker, it uses the default value (false) which is wrong.
  10. Since Service Workers are guaranteed to ALWAYS be a web secure
  11. context, this change explicitly sets it to true when restoring a
  12. serialized policy.
  13. See: https://w3c.github.io/webappsec-secure-contexts/#examples-service-workers
  14. Bug: 387258077,383070811
  15. Change-Id: I75efe895662ab4e6d68cacace6d05e004c5dfd33
  16. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6236205
  17. Reviewed-by: Hiroki Nakagawa <[email protected]>
  18. Reviewed-by: Dave Tapuska <[email protected]>
  19. Commit-Queue: Patrick Meenan <[email protected]>
  20. Cr-Commit-Position: refs/heads/main@{#1416795}
  21. diff --git a/content/browser/renderer_host/policy_container_host.cc b/content/browser/renderer_host/policy_container_host.cc
  22. index 5f62b1a274bab7028beb9836f88805e7b5a83e2c..f16f56d8d5f0c4e9bc164c546eee8c28f6856693 100644
  23. --- a/content/browser/renderer_host/policy_container_host.cc
  24. +++ b/content/browser/renderer_host/policy_container_host.cc
  25. @@ -136,9 +136,11 @@ PolicyContainerPolicies::PolicyContainerPolicies(
  26. allow_cross_origin_isolation(allow_cross_origin_isolation) {}
  27. PolicyContainerPolicies::PolicyContainerPolicies(
  28. - const blink::mojom::PolicyContainerPolicies& policies)
  29. + const blink::mojom::PolicyContainerPolicies& policies,
  30. + bool is_web_secure_context)
  31. : referrer_policy(policies.referrer_policy),
  32. ip_address_space(policies.ip_address_space),
  33. + is_web_secure_context(is_web_secure_context),
  34. content_security_policies(
  35. mojo::Clone(policies.content_security_policies)),
  36. cross_origin_embedder_policy(policies.cross_origin_embedder_policy),
  37. diff --git a/content/browser/renderer_host/policy_container_host.h b/content/browser/renderer_host/policy_container_host.h
  38. index 394bd53bb5c1dfea5abe24b9047eb190884c2648..7add42348ef28079196b447feda78210815d1551 100644
  39. --- a/content/browser/renderer_host/policy_container_host.h
  40. +++ b/content/browser/renderer_host/policy_container_host.h
  41. @@ -49,7 +49,8 @@ struct CONTENT_EXPORT PolicyContainerPolicies {
  42. bool allow_cross_origin_isolation);
  43. explicit PolicyContainerPolicies(
  44. - const blink::mojom::PolicyContainerPolicies& policies);
  45. + const blink::mojom::PolicyContainerPolicies& policies,
  46. + bool is_web_secure_context);
  47. // Used when loading workers from network schemes.
  48. // WARNING: This does not populate referrer policy.
  49. diff --git a/content/browser/service_worker/service_worker_registry.cc b/content/browser/service_worker/service_worker_registry.cc
  50. index aa1e8fb5d1b3eef93b799f29cc89e15315507d2d..68b5c2ba114aa084c5ad6bc2e4fd12d44393ed77 100644
  51. --- a/content/browser/service_worker/service_worker_registry.cc
  52. +++ b/content/browser/service_worker/service_worker_registry.cc
  53. @@ -1084,7 +1084,8 @@ ServiceWorkerRegistry::GetOrCreateRegistration(
  54. if (data.policy_container_policies) {
  55. version->set_policy_container_host(
  56. base::MakeRefCounted<PolicyContainerHost>(
  57. - PolicyContainerPolicies(*data.policy_container_policies)));
  58. + PolicyContainerPolicies(*data.policy_container_policies,
  59. + /*is_web_secure_context=*/true)));
  60. }
  61. if (data.router_rules) {
  62. auto error = version->SetupRouterEvaluator(*data.router_rules);