Fix document.referrer on about:blank creation

The HTML Standard assigns `document.referrer` [1] in two ways:
  1.) During Document/browsing context creation
  2.) Upon navigation to a new Document

For creation (1):
Per the HTML Standard's "create a new browsing context" algorithm [2] step 3, all new browsing contexts with a non-null creator (always same-BCG) have their "creator URL" set to the creator document's full URL, unredacted and subjected to no referrer policy sanitization. Later in step 20, we set the referrer of the newly-created document to the newly-created browsing context's creator URL.

For navigation (2):
In "create and initialize a Document object", with the referrer from
"navigation params" [3]

----

In Blink, we handle `document.referrer` assignment the same for both creation and navigation; we simply set `DocumentLoader::referrer_` to what the resulting `WebNavigationParams` carries [4], and we don't do anything special for the browsing context creation case. This leads to the final `document.referrer` on Documents being created in new BCs actually being incorrectly subjected to referrer policy sanitization/redaction.

Due to existing issues, Chrome does not perfectly follow the HTML Standard for creation of new browsing contexts. In short, for iframes we create a new browsing context/document [5] and immediately navigate it to about:blank [6]. This navigation commits synchronously via a special
path that tries to make up for Blink's mismatch with the spec [7].

During this synchronous about:blank navigation, the request's referrer is computed as "" (in FrameLoadRequest::ctor), because the origin of the "about:blank" URL is opaque and therefore cross-origin with the embedder, and the default referrer policy is `strict-origin-when-cross-origin`.

For newly created windows (with openers, since this is only relevant for windows with "creators"), something very similar happens. We create a FrameLoadRequest whose referrer gets set to "" (in FrameLoadRequest::ctor as well as [8]), and we perform the special-case synchronous navigation which ends up with the resulting document having an empty referrer, just like in the iframe case.

----

This CL fixes the above issues by modifying `RenderFrameImpl::SynchronouslyCommitAboutBlankForBug778318()` to find the initiator frame (should be equivalent to the spec's "creator" Document), if it is local (should be the case for about:blank subframes and new windows w/o "noopener"), and sets the navigation params's referrer member to the initiator Document's full unredacted URL. This will be used to set the eventual `DocumentLoader::referrer_` member when the synchronous navigation commits, which will be used to reflect the correct value to `document.referrer`.

In cases where we don't go through Blink's special sync navigation case, `document.referrer` is unchanged.

----

[1]: https://html.spec.whatwg.org/multipage/dom.html#dom-document-referrer and https://html.spec.whatwg.org/multipage/dom.html#the-document's-referrer
[2]: https://html.spec.whatwg.org/multipage/browsers.html#creating-a-new-browsing-context
[3]: https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigating-across-documents:the-document's-referrer-2
[4]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/loader/document_loader.cc;l=322;drc=5dffcc4991ab32edc7dbc99c3b4685882c029ab0
[5]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/html_frame_owner_element.cc;l=827-828;drc=6fd9edfbb85bc5fb2ed8f9300abe83cd03ab54b7
[6]: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/html/html_frame_owner_element.cc;l=862-863;drc=6fd9edfbb85bc5fb2ed8f9300abe83cd03ab54b7
[7]: https://source.chromium.org/chromium/chromium/src/+/main:content/renderer/render_frame_impl.h;l=929-953;drc=5575ddb21068841ba19e1ea957b4fdb5adcd0250
[8]: https://source.chromium.org/chromium/chromium/src/+/main:content/renderer/render_view_impl.cc;l=290-292;drc=5dffcc4991ab32edc7dbc99c3b4685882c029ab0

Bug: 1075729
Change-Id: I6c01ece280bc8702dda6ba60015eaafb3989f3d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3763042
Commit-Queue: Dominic Farolino <dom@chromium.org>
Reviewed-by: Daniel Rubery <drubery@chromium.org>
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1025876}
1 file changed
tree: 28632924bedd4f514c07d6218339b82078515d40
  1. .github/
  2. .well-known/
  3. accelerometer/
  4. accessibility/
  5. accname/
  6. acid/
  7. ambient-light/
  8. animation-worklet/
  9. annotation-model/
  10. annotation-protocol/
  11. annotation-vocab/
  12. apng/
  13. appmanifest/
  14. attribution-reporting/
  15. audio-output/
  16. background-fetch/
  17. BackgroundSync/
  18. badging/
  19. battery-status/
  20. beacon/
  21. bluetooth/
  22. clear-site-data/
  23. client-hints/
  24. clipboard-apis/
  25. close-watcher/
  26. common/
  27. compat/
  28. compression/
  29. compute-pressure/
  30. conformance-checkers/
  31. console/
  32. contacts/
  33. content-dpr/
  34. content-index/
  35. content-security-policy/
  36. contenteditable/
  37. cookie-store/
  38. cookies/
  39. core-aam/
  40. cors/
  41. credential-management/
  42. css/
  43. custom-elements/
  44. custom-state-pseudo-class/
  45. delegated-ink/
  46. density-size-correction/
  47. deprecation-reporting/
  48. device-memory/
  49. direct-sockets/
  50. docs/
  51. document-policy/
  52. dom/
  53. domparsing/
  54. domxpath/
  55. dpub-aam/
  56. dpub-aria/
  57. editing/
  58. element-timing/
  59. encoding/
  60. encoding-detection/
  61. encrypted-media/
  62. entries-api/
  63. event-timing/
  64. eventsource/
  65. eyedropper/
  66. feature-policy/
  67. fetch/
  68. file-system-access/
  69. FileAPI/
  70. focus/
  71. font-access/
  72. fonts/
  73. forced-colors-mode/
  74. fs/
  75. fullscreen/
  76. gamepad/
  77. generic-sensor/
  78. geolocation-API/
  79. geolocation-sensor/
  80. graphics-aam/
  81. gyroscope/
  82. hr-time/
  83. html/
  84. html-longdesc/
  85. html-media-capture/
  86. idle-detection/
  87. imagebitmap-renderingcontext/
  88. images/
  89. import-maps/
  90. IndexedDB/
  91. inert/
  92. infrastructure/
  93. input-device-capabilities/
  94. input-events/
  95. installedapp/
  96. interfaces/
  97. intersection-observer/
  98. intervention-reporting/
  99. is-input-pending/
  100. js/
  101. js-self-profiling/
  102. keyboard-lock/
  103. keyboard-map/
  104. largest-contentful-paint/
  105. layout-instability/
  106. lifecycle/
  107. loading/
  108. longtask-timing/
  109. magnetometer/
  110. managed/
  111. mathml/
  112. measure-memory/
  113. media/
  114. media-capabilities/
  115. media-playback-quality/
  116. media-source/
  117. mediacapture-fromelement/
  118. mediacapture-handle/
  119. mediacapture-image/
  120. mediacapture-insertable-streams/
  121. mediacapture-record/
  122. mediacapture-region/
  123. mediacapture-streams/
  124. mediasession/
  125. merchant-validation/
  126. mimesniff/
  127. mixed-content/
  128. mst-content-hint/
  129. native-io/
  130. navigation-api/
  131. navigation-timing/
  132. netinfo/
  133. network-error-logging/
  134. notifications/
  135. old-tests/
  136. orientation-event/
  137. orientation-sensor/
  138. page-lifecycle/
  139. page-visibility/
  140. paint-timing/
  141. parakeet/
  142. payment-handler/
  143. payment-method-basic-card/
  144. payment-method-id/
  145. payment-request/
  146. performance-timeline/
  147. periodic-background-sync/
  148. permissions/
  149. permissions-policy/
  150. permissions-request/
  151. permissions-revoke/
  152. picture-in-picture/
  153. pointerevents/
  154. pointerlock/
  155. portals/
  156. preload/
  157. presentation-api/
  158. priority-hints/
  159. private-click-measurement/
  160. proximity/
  161. push-api/
  162. quirks/
  163. referrer-policy/
  164. remote-playback/
  165. reporting/
  166. requestidlecallback/
  167. resize-observer/
  168. resource-timing/
  169. resources/
  170. sanitizer-api/
  171. savedata/
  172. scheduler/
  173. screen-capture/
  174. screen-details/
  175. screen-orientation/
  176. screen-wake-lock/
  177. scroll-animations/
  178. scroll-to-text-fragment/
  179. secure-contexts/
  180. secure-payment-confirmation/
  181. selection/
  182. serial/
  183. server-timing/
  184. service-workers/
  185. shadow-dom/
  186. shape-detection/
  187. shared-storage/
  188. signed-exchange/
  189. speculation-rules/
  190. speech-api/
  191. storage/
  192. storage-access-api/
  193. streams/
  194. subapps/
  195. subresource-integrity/
  196. svg/
  197. svg-aam/
  198. timing-entrytypes-registry/
  199. tools/
  200. touch-events/
  201. trust-tokens/
  202. trusted-types/
  203. ua-client-hints/
  204. uievents/
  205. upgrade-insecure-requests/
  206. url/
  207. urlpattern/
  208. user-timing/
  209. vibration/
  210. video-rvfc/
  211. virtual-keyboard/
  212. visual-viewport/
  213. wai-aria/
  214. wasm/
  215. web-animations/
  216. web-bundle/
  217. web-locks/
  218. web-nfc/
  219. web-otp/
  220. web-share/
  221. webaudio/
  222. webauthn/
  223. webcodecs/
  224. WebCryptoAPI/
  225. webdriver/
  226. webgl/
  227. webgpu/
  228. webhid/
  229. webidl/
  230. webmessaging/
  231. webmidi/
  232. webnn/
  233. webrtc/
  234. webrtc-encoded-transform/
  235. webrtc-extensions/
  236. webrtc-ice/
  237. webrtc-identity/
  238. webrtc-priority/
  239. webrtc-stats/
  240. webrtc-svc/
  241. websockets/
  242. webstorage/
  243. webtransport/
  244. webusb/
  245. webvr/
  246. webvtt/
  247. webxr/
  248. window-placement/
  249. workers/
  250. worklets/
  251. x-frame-options/
  252. xhr/
  253. .azure-pipelines.yml
  254. .gitattributes
  255. .gitignore
  256. .mailmap
  257. .taskcluster.yml
  258. CODE_OF_CONDUCT.md
  259. CODEOWNERS
  260. CONTRIBUTING.md
  261. LICENSE.md
  262. lint.ignore
  263. README.md
  264. webkit-mask-box-enumeration.html
  265. wpt
  266. wpt.py
README.md

The web-platform-tests Project

Taskcluster CI Status documentation manifest Python 3

The web-platform-tests Project is a cross-browser test suite for the Web-platform stack. Writing tests in a way that allows them to be run in all browsers gives browser projects confidence that they are shipping software that is compatible with other implementations, and that later implementations will be compatible with their implementations. This in turn gives Web authors/developers confidence that they can actually rely on the Web platform to deliver on the promise of working across browsers and devices without needing extra layers of abstraction to paper over the gaps left by specification editors and implementors.

The most important sources of information and activity are:

  • github.com/web-platform-tests/wpt: the canonical location of the project's source code revision history and the discussion forum for changes to the code
  • web-platform-tests.org: the documentation website; details how to set up the project, how to write tests, how to give and receive peer review, how to serve as an administrator, and more
  • wpt.live: a public deployment of the test suite, allowing anyone to run the tests by visiting from an Internet-enabled browser of their choice
  • wpt.fyi: an archive of test results collected from an array of web browsers on a regular basis
  • Real-time chat room: the wpt:matrix.org matrix channel; includes participants located around the world, but busiest during the European working day.
  • Mailing list: a public and low-traffic discussion list
  • RFCs: a repo for requesting comments on substantial changes that would impact other stakeholders or users; people who work on WPT infra are encouraged to watch the repo.

If you'd like clarification about anything, don't hesitate to ask in the chat room or on the mailing list.

Setting Up the Repo

Clone or otherwise get https://github.com/web-platform-tests/wpt.

Note: because of the frequent creation and deletion of branches in this repo, it is recommended to “prune” stale branches when fetching updates, i.e. use git pull --prune (or git fetch -p && git merge).

Running the Tests

See the documentation website and in particular the system setup for running tests locally.

Command Line Tools

The wpt command provides a frontend to a variety of tools for working with and running web-platform-tests. Some of the most useful commands are:

  • wpt serve - For starting the wpt http server
  • wpt run - For running tests in a browser
  • wpt lint - For running the lint against all tests
  • wpt manifest - For updating or generating a MANIFEST.json test manifest
  • wpt install - For installing the latest release of a browser or webdriver server on the local machine.
  • wpt serve-wave - For starting the wpt http server and the WAVE test runner. For more details on how to use the WAVE test runner see the documentation.

Windows Notes

On Windows wpt commands must be prefixed with python or the path to the python binary (if python is not in your %PATH%).

python wpt [command]

Alternatively, you may also use Bash on Ubuntu on Windows in the Windows 10 Anniversary Update build, then access your windows partition from there to launch wpt commands.

Please make sure git and your text editor do not automatically convert line endings, as it will cause lint errors. For git, please set git config core.autocrlf false in your working tree.

Publication

The master branch is automatically synced to wpt.live and w3c-test.org.

Contributing

Save the Web, Write Some Tests!

Absolutely everyone is welcome to contribute to test development. No test is too small or too simple, especially if it corresponds to something for which you've noted an interoperability bug in a browser.

The way to contribute is just as usual:

  • Fork this repository (and make sure you're still relatively in sync with it if you forked a while ago).
  • Create a branch for your changes: git checkout -b topic.
  • Make your changes.
  • Run ./wpt lint as described above.
  • Commit locally and push that to your repo.
  • Create a pull request based on the above.

Issues with web-platform-tests

If you spot an issue with a test and are not comfortable providing a pull request per above to fix it, please file a new issue. Thank you!