Repository navigation
fix(navigation): apply the document and link referrer policy to top-level navigations - #2823
lanyue-llk wants to merge 2 commits into
Conversation
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of a0c7113
Changes needed (2)
Picture: pending.
The direction is right for moli. Attaching the source Document as the initiator at the one place where same-realm location navigations are recorded fixes the cause rather than each caller, and it uses the existing policy lookup that subresources already use (meta, then header). Link precedence follows the spec: rel=noreferrer > a valid referrerpolicy > the Document policy, and an invalid or empty attribute falls back. Each redirect hop's Referrer-Policy still applies, because the policy goes into referrer_policy and update_referrer_for_redirect overwrites that field per hop. CDP Page.navigate never reaches record_pending_location_navigation_request, so it is unaffected. The extra cost applies only to page-initiated navigations. The new test checks the Referer header as the server receives it and would fail on main.
-
default_action.rs:1909-1922+targets.rs:711-725: the link policy stays set while page script runs.anchor_click_navigationdispatches the Navigation APInavigateevent synchronously (dispatch_top_level_navigation_event_with_source_element, targets.rs:711) before it queues the link's own navigation. If anavigatehandler callse.preventDefault(); location.href = '/x',/xis recorded with the link's policy instead of the Document's. When the link is looser than the page, for example<meta name=referrer content=no-referrer>with<a referrerpolicy=unsafe-url>, that unrelated navigation sends the full URL. This is the kind of leak this PR is meant to close. Smallest fix: drop the host-wide hold. Read the anchor'srel/referrerpolicyfromsource_handlewhere the link's own top-level navigation is recorded (queue_top_level_location_navigation, and the same-URLlocationbranch at default_action.rs:1985) and pass it in. Alternatively,take()the field around thenavigateevent dispatch and restore it afterwards. -
navigation.rs:176: reload and Navigation API traversal now commitdocument.referreras the current page's own URL.record_pending_location_navigation_requestis also used bylocation.reload()(location_navigation.rs:673, kindReload) and bynavigation.back()/traverseTo()(navigation_traversal_execution.rs:58). On the CDP path, the initiator now feedsRendererMainDocumentCommitSeed::resolve(navigation_outcome.rs:172-175), sodocument.referrerbecomesreferrer_value(current URL, …). Repro:/alinks to/b, then/brunslocation.reload(). With v1.1.23 over CDP,document.referreron/bis""both before and after the reload. On this branch it becomeshttp://host/bafter the reload. Chromium keeps the entry's original referrer (http://host/a). The new value is a self-referrer and is wrong in a new way. Smallest fix: attach the Document initiator only to Navigate-kind non-traversal navigations, and leaveReloadand traversal callers onNoneas they are on main. Reload and traversal referrers belong to the remaining #2790 work. Add a CDP-path assertion. The new test only exercisesmoli fetch, while thenavigation.rschange mainly affects the CDP path.
CI: Clippy, Format, harness and Windows checks pass. Nextest, the release builds and the CDP smoke test are still pending. The body correctly says Part of #2790 rather than claiming to close it.
lanyue-llk
left a comment
There was a problem hiding this comment.
Independent review of 8119a6d
No blocking findings
Both round-1 issues are fixed in the code:
- The link-policy leak is gone. Nothing is held host-wide any more.
hyperlink_referrer_policy(handle)is read only from the source element of the navigation being recorded:targets.rs:95-98for the_top/current hyperlink, andlocation_navigation.rs:684-690when the Location path receives a source element. Anavigatehandler'slocation.href=arrives withsource_element = None, so it gets the Document's policy. The wire casenavigate-handlercovers this. - Reload no longer records an initiator (
location_navigation.rs:684,!matches!(kind, Reload)). Traversals (navigation_traversal_execution.rs:58) andwindow.openjavascript: queuing (popups/renderer_owned.rs:31) are untouched, so they behave as on main. The renderer testlocation_navigations_record_a_document_initiator_but_reloads_do_notfails on main for the first assertion and protects the reload half. set_pending_location_navigation_document_initiatoralways follows arecord_pending_location_navigation*call, and that call replaces the pending entry unconditionally (context_host/navigation.rs:162-196). So it cannot overwrite an initiator from another realm on an older pending navigation.
Coverage of page-started paths: meta refresh and window.open(_self/_top) go through the same Location function, so they now carry the Document initiator as well. Same-process child-frame sources and iframe src keep main's behaviour, as the PR states. These gaps are not regressions; they belong to the remaining #2790 scope.
Cost: the default path does no new work. Pages that do not navigate are untouched. A page-started navigation adds one attribute lookup and one initiator, and reload now does less than the round-1 head. The numbers were measured on an earlier head, but they remain plausible for this diff.
Optional:
- The picture is out of date. Its Fix panel still says "
<a>rel=noreferrer / referrerpolicy held during activation" (default_action.rs) and "record_pending_location_navigation_request attaches the page Document". The current design reads the policy per link attargets.rs/the Location path and attaches the initiator only at page-started sites, with no reload initiator. Please regenerate that panel and the test line, which should also name the renderer test. - CI was still pending when I reviewed (Nextest, Clippy, CDP smoke, Build release). Please confirm they are green before merge.
CI Regression ReportSource CI run · source state at render:
Release regression — ✅ HEAD/base failures 0/0; raw binary +0.003027%Package and image size
Startup latency and PSS
Concurrency matrix
Frontend differential — ✅ 1,020/1,020 cases matched; 0 issues
Agent episodes · Moli vs Chromium — ✅ 8/8 Moli episodes passed; 0 failures
Runtime and CDP session contracts — ✅ 26 contract cases; 0 failures
CDP smoke — ✅ 118/118 groups passed; 1,784 scenariosWorkers: 4 · cumulative group time: 479.60 s · failed groups: 0
WebMainBench · 545 pages — ✅ 545/545 completed; 0 unexpected failures
Frozen HTML · Linux · Diagnostics: All artifact fields are parsed by the trusted default-branch renderer; missing or invalid inputs remain visible as unavailable. |
Spider Bench A/B✅ All benchmark browser service runs completed; results are informational. Public HEAD: 184 / 240 rows; 38 / 48 sites produced rows; 10 unexpected empty sites. ✅ Deterministic fixture contract is clean. Common ancestor Public 48-site run · informational
Public-site content, timing, and memory are noisy. This single A/B run reports evidence only; site outcome counts explain missing rows without treating them as a deterministic regression. CPU and memory timelinesThese are bounded 40-point views of the same complete process-tree samples used by the HTML report. CPU uses 100% per occupied logical core; memory lines are RSS first and PSS second when complete PSS samples are available. Basexychart-beta
title "Base CPU"
x-axis "Elapsed seconds" [1.539, 3.541, 5.043, 7.047, 8.55, 10.053, 12.055, 13.558, 14.059, 15.56, 17.062, 18.565, 20.566, 22.067, 23.568, 25.57, 27.072, 29.074, 30.577, 32.078, 33.079, 34.081, 35.583, 37.586, 39.089, 40.591, 42.595, 44.098, 46.1, 47.602, 49.104, 51.107, 52.609, 54.11, 56.112, 57.614, 59.616, 60.117]
y-axis "CPU percent" 0 --> 200
line [133.82, 89.93, 129.92, 19.96, 113.82, 117.89, 109.94, 7.98, 0, 4, 13.97, 19.94, 10, 95.98, 37.98, 2, 3.99, 31.93, 61.84, 135.82, 107.89, 107.78, 103.86, 95.8, 103.85, 83.95, 53.88, 103.82, 2, 37.94, 25.97, 5.99, 21.97, 12, 93.89, 151.75, 128.05, 173.8]
xychart-beta
title "Base memory: RSS then PSS"
x-axis "Elapsed seconds" [0.038, 1.539, 3.541, 5.043, 7.047, 8.55, 10.053, 12.055, 13.558, 14.059, 15.56, 17.062, 18.565, 20.566, 22.067, 23.568, 25.57, 27.072, 29.074, 30.577, 32.078, 33.079, 34.081, 35.583, 37.586, 39.089, 40.591, 42.595, 44.098, 46.1, 47.602, 49.104, 51.107, 52.609, 54.11, 56.112, 57.614, 59.616, 60.117, 61.024]
y-axis "Memory MiB" 0 --> 500
line [13.8, 100.78, 113.06, 152.13, 138.74, 123.68, 152.25, 136.95, 119.3, 119.16, 116.57, 119.63, 120.89, 122.19, 146.27, 123.16, 123.83, 123.83, 130.38, 157.72, 152.86, 270.79, 195.49, 137.2, 193.34, 137.42, 143.19, 158.25, 244.41, 222.56, 234, 231.05, 228.91, 229.18, 152.19, 148.22, 164.07, 158.99, 159.37, 0]
line [10.5, 97.96, 109.37, 148.47, 135.41, 119.98, 148.47, 133.24, 115.69, 115.45, 112.86, 115.92, 117.18, 118.69, 142.56, 119.67, 120.11, 120.1, 126.65, 153.88, 149.18, 267.09, 191.78, 133.46, 189.56, 133.83, 139.45, 154.6, 240.68, 218.83, 230.07, 227.32, 225.17, 225.56, 148.46, 144.57, 160.34, 157.38, 155.65, 0]
HEADxychart-beta
title "HEAD CPU"
x-axis "Elapsed seconds" [1.542, 3.044, 3.545, 4.546, 5.046, 6.548, 8.552, 10.055, 12.058, 13.56, 15.063, 17.064, 18.566, 20.069, 22.071, 23.574, 25.076, 27.078, 27.579, 28.58, 30.582, 32.084, 33.586, 35.59, 37.09, 38.592, 40.594, 42.095, 43.596, 45.599, 47.101, 48.604, 50.608, 52.109, 54.11, 55.613, 57.115, 59.119]
y-axis "CPU percent" 0 --> 200
line [125.64, 109.95, 107.87, 139.86, 129.92, 115.95, 99.86, 49.87, 135.72, 21.99, 2, 2, 5.99, 101.89, 29.92, 1.99, 3.99, 4, 0, 121.91, 111.92, 101.9, 103.92, 57.89, 76, 87.85, 32.01, 65.95, 105.9, 2, 23.96, 29.95, 9.99, 13.99, 9.99, 107.79, 169.71, 133.74]
xychart-beta
title "HEAD memory: RSS then PSS"
x-axis "Elapsed seconds" [0.04, 1.542, 3.044, 3.545, 4.546, 5.046, 6.548, 8.552, 10.055, 12.058, 13.56, 15.063, 17.064, 18.566, 20.069, 22.071, 23.574, 25.076, 27.078, 27.579, 28.58, 30.582, 32.084, 33.586, 35.59, 37.09, 38.592, 40.594, 42.095, 43.596, 45.599, 47.101, 48.604, 50.608, 52.109, 54.11, 55.613, 57.115, 59.119, 60.337]
y-axis "Memory MiB" 0 --> 500
line [13.79, 98.46, 128.58, 125.37, 132.86, 155.89, 135.07, 128.28, 140.11, 142.72, 140.06, 121.86, 122.95, 123.42, 145.4, 133, 126.02, 126.02, 125.82, 125.84, 144.17, 147.47, 244.12, 199.08, 145.79, 182.19, 137.65, 130.78, 164.09, 248.96, 226.31, 236.99, 234.24, 232.03, 232.36, 150.66, 145.46, 165.2, 174.46, 0]
line [10.23, 94.75, 124.91, 121.67, 129.16, 152.18, 131.32, 124.53, 136.44, 138.93, 136.36, 118.08, 119.16, 119.63, 141.61, 129.21, 122.23, 122.23, 122.03, 122.05, 140.46, 143.65, 239.83, 195.36, 142, 178.39, 133.88, 127.02, 160.35, 245.19, 222.54, 233.22, 230.48, 228.26, 228.64, 146.84, 141.73, 161.4, 170.73, 0]
Deterministic fixture · required contractThe fixture exercises 15 routes: 8 are expected to emit rows and 7 intentionally exercise empty, loading, or timeout behavior.
Full HTML, JSON, CSV, logs, and page snapshots: workflow run and full The public-web A/B is informational. The exact HEAD fixture contract runs as a separate required CI check; timing and public-site content deltas remain non-blocking. |
Sequential Navigation Soak A/B✅ HEAD completed the 200-navigation resilience and memory observation. One browser process, one target, and one CDP session navigate CSDN → SegmentFault → Huaban → example.com repeatedly. This run issued 200 Common ancestor Session resilience
A public-page failure is reported separately from an unrecoverable session. The soak requires all navigation attempts, zero failed recovery, zero lifecycle/network ordering violations, and complete resource evidence. Process-tree memory
HEAD memory by 50-navigation quarter
Raw reports and per-navigation boundary samples: workflow run and full Public-site timing and memory are observational. Use the A/B deltas and trend shape as evidence, not as a deterministic performance threshold. |
8119a6d to
98b68ce
Compare
Track: Trajectory Replay (Browser Eval). Replaces part of #758.

Part of #2790 (top-level navigations; iframe `src` loads are not covered here). Replaces part of #758.Problem. Link,
locationand form navigations sent the full page URL asReferereven when the page asked forno-referrerororigin, whether through<meta name=referrer>, theReferrer-Policyheader, the link'sreferrerpolicyattribute orrel=noreferrer. This leaks paths, tokens and query strings to the destination. Repro:moli fetch http://127.0.0.1:8000/meta-link --wait networkidle --dump markdown, where the page has<meta name=referrer content=no-referrer>and clicks a link to/t;/treceivedReferer: http://127.0.0.1:8000/meta-link. Subresourcefetch()already honoured the policy.Reproduce (steps from #2790)
The server returns
<p>target</p>for/tand logs theRefererit receives. Case pages:meta-link:<meta name=referrer content=no-referrer><a id=l href="/t">go</a><script>setTimeout(()=>l.click(),50)</script>hdr-link: the same without the meta, served withReferrer-Policy: no-referrerattr-link:<a id=l referrerpolicy=no-referrer href="/t">, then clickrel-link:<a id=l rel=noreferrer href="/t">, then clickorigin-link:<meta name=referrer content=origin>, then a link clickmeta-loc: the meta, thensetTimeout(()=>location.href="/t",50)meta-form: the meta, then<form id=f action=/t></form><script>setTimeout(()=>f.submit(),50)</script>meta-iframe: the meta, then<iframe src="/t">(or
Page.navigateover CDP)Expected (Chromium)
/treceives noRefererin the no-referrer cases, andhttp://host/inorigin-link.Actual
Every case sends the full page URL, for example
REFERER http://127.0.0.1:18780/meta-link. Subresourcefetch()honors the meta policy, so only navigations are affected.Change.
native_bridge/context_host/navigation.rs: a same-realm location navigation recorded no initiator, so the request fell back to the default policy. The newset_pending_location_navigation_document_initiator(link_policy)marks the page Document as theRendererNavigationInitiatorof the navigation that was just recorded. Its policy is the link's own policy if one is given, otherwise the existingdocument_referrer_policy_for_native_document(meta, then the response header).locationsetter/assign/replace (notreload()), a hyperlink's top-level target (activation/targets.rs), form submission (forms/submission.rsand the top-target branch indefault_action.rs), andnavigation.navigate(). Reloads and history traversals record no initiator, exactly as on main, so the commit keeps its previousdocument.referrer. Navigations from another realm still set their own source, as before.PageScriptHost::hyperlink_referrer_policy(handle)reads an<a>/<area>'srel=noreferrer(→no-referrer) orreferrerpolicyattribute. It is applied only to that link's own navigation, at the point where that navigation is recorded: the_toptarget, and thelocationpath when the source element is the link. No host-wide state is held, so a navigation that anavigatehandler starts instead uses the Document's policy.runtime/page_vm/followed_navigation.rs: the CLI's followed navigation set only the initiator URL. It now also applies the initiator's request metadata (referrer policy), as the CDP path already does (runtime_load.rs).Verification.
Refererreceived by/t(local server,moli fetch … --wait networkidle):<meta name=referrer content=no-referrer>+ linkReferrer-Policy: no-referrerheader + link<a referrerpolicy=no-referrer><a rel=noreferrer>origin+ linkhttp://127.0.0.1:18790/location.href=form.submit()top_level_navigations_apply_the_document_and_link_referrer_policy(moli-core/tests/fetch/security.rs) runs ten cases and asserts theRefererheader on the wire. Besides the eight above, it checks that a link withreferrerpolicy=unsafe-urlon ano-referrerpage sends the full URL, and that anavigatehandler which cancels that link and assignslocationsends noReferer.location_navigations_record_a_document_initiator_but_reloads_do_not(renderer):location.href=records the Document initiator andlocation.reload()records none.moli serve+Runtime.evaluate: after a link click,document.referreris nowhttp://127.0.0.1:18790/plain-link(v1.1.23:""). After a followinglocation.reload()it is"", the same as v1.1.23, so reload no longer turns the page's own URL into the referrer.cargo nextest run -p moli-core --test fetch -E 'test(referrer)': 2 passed.cargo nextest run -p moli-core -p moli -E 'test(referrer) | test(referer) | test(navigat) | test(location) | test(form_submi) | test(reload)': 293 passed.cargo nextest run -p moli-renderer-v8 -p moli-protocol -E 'test(location_navigations_record) | test(followed) | test(referrer) | test(referer) | test(location_navigation) | test(hyperlink) | test(anchor) | test(history) | test(reload)': 648 passed.cargo fmt --allclean;cargo clippy -p moli-renderer-v8 -p moli-core --all-targets --all-features -- -D warningsclean (workspace clippy not run locally).srcloads are a separate request path and stay recorded on Link, form, location and iframe navigations send a full Referer despite no-referrer/origin policies #2790.Cost. Each page-started top-level navigation builds one small initiator (a URL clone, an origin, and a policy lookup on the Document). Pages that do not navigate are unaffected. Debug builds of main cbf4d01 and this branch, same profile,
/usr/bin/time -l, alternating runs, median of 7:--wait networkidle--wait networkidle