Repository navigation
fix(tiles): enforce request destination provenance #1560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9ea3911
f689640
155af17
b165786
27305b1
b4eea8c
d32db9d
d999767
3b92d83
a5510b0
d3a1cf5
404d4ad
041760d
a5be2aa
85b3fec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -597,11 +597,24 @@ async fn fetch_bytes( | |
| still: Option<rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::cache::Still>, | ||
| omit: &'static [u16], | ||
| ) -> Result<Vec<u8>, String> { | ||
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::address::Reach; | ||
| fetch_reached(url, Reach::Local, capture, still, omit).await.map(|fetched| fetched.bytes) | ||
| } | ||
|
|
||
| /// GET carries its inherited reach into final URL preparation and returns the normalized | ||
| /// credential-free destination with its bytes. Fetch never follows an opaque redirect. | ||
| async fn fetch_reached( | ||
| url: &str, | ||
| ceiling: rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::address::Reach, | ||
| capture: Capture, | ||
| still: Option<rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::cache::Still>, | ||
| omit: &'static [u16], | ||
| ) -> Result<rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::cache::Fetched, String> { | ||
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::{cache::RequestDiagnostics, failure::Failure}; | ||
| let mut diagnostics = RequestDiagnostics::with_capture(url, "GET", capture); | ||
| diagnostics.omit_statuses(omit); | ||
| let answer = async { | ||
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::{cache, logins}; | ||
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::{address, cache, logins}; | ||
| let (promise, abort, range, tail, max, url, bound, authenticated) = crate::request::prepare_and_send( | ||
| &still, | ||
| || async { | ||
|
|
@@ -617,6 +630,7 @@ async fn fetch_bytes( | |
| let bound = url; | ||
| let prepared = rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::s3::prepare(logins::inner(url))?; | ||
| let url = prepared.url.as_str(); | ||
| let destination = check_destination(url, ceiling)?; | ||
| // An ArcGIS sign-in's token, for the portal and the servers it covers, renewed first when it | ||
| // is about to expire. It goes as the request's `token` parameter, not a header: ArcGIS's | ||
| // query endpoints answer the header's CORS preflight with an error. | ||
|
|
@@ -631,6 +645,10 @@ async fn fetch_bytes( | |
| if prepared.signed { None } else { rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::arcgis_auth::with_token(login_url) }; | ||
| // Only the request carries credentials: messages and cache keys keep the original address. | ||
| let request = arcgis.as_deref().unwrap_or(login_url); | ||
| // URL parsing in a browser can normalize a numeric or escaped hostname. Judge | ||
| // that actual destination against the already checked, prepared address. | ||
| let normalized = web_sys::Url::new(request).map_err(|_| "not a valid request address")?; | ||
| address::check_reach(&normalized.href(), ceiling)?; | ||
| let authenticated = prepared.signed || arcgis.is_some() || login.is_some(); | ||
| let err = |e: wasm_bindgen::JsValue| { | ||
| if authenticated { "the browser couldn't process the authenticated request".to_string() } else { format!("{e:?}") } | ||
|
|
@@ -662,16 +680,15 @@ async fn fetch_bytes( | |
| } | ||
| init.set_headers(&headers); | ||
| } | ||
| // A signed or authorized request goes only where its credentials are for. | ||
| if authenticated { | ||
| init.set_redirect(web_sys::RequestRedirect::Error); | ||
| } | ||
| // Fetch hides a manual redirect's Location, so the app cannot check its next | ||
| // destination. Refuse it instead of letting the browser follow it unchecked. | ||
| init.set_redirect(if authenticated { web_sys::RequestRedirect::Error } else { web_sys::RequestRedirect::Manual }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Behavior change (medium confidence): unauthenticated browser requests now use The PR says this is intentional, and the error text and docs state it. Please confirm it is an accepted regression. If it is, consider naming it in the PR description and in the changelog so users who hit it know to use the final address.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intentional: Fetch hides a manual redirect's destination, so following it would bypass the destination check. The map guide now names HTTP-to-HTTPS and CDN redirects, and tells users to use the final address. There is no changelog in this repository. f689640 Workspace CI, strict WebAssembly and all-file hooks pass.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redirect refusal applies to every browser fetch, but the docs name only tiles, styles, TileJSON and sprites.
The earlier thread accepted the behavior for tile, style, TileJSON and sprite requests. The docs in Suggest either documenting these in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Network downloads documentation and PR compatibility notes now describe redirect refusal for all browser GET requests, including file downloads, fonts, service documents, and PMTiles/COG range reads. They give the final-address and external-download workarounds. The related long type path in fetch_bytes is shortened in this batch. Fixed in b1657868. All 346 tile tests, workspace CI, strict WebAssembly and all-file hooks pass. |
||
| // A credential-bearing address goes nowhere else: no referrer from it, no cookies with it. | ||
| if arcgis.is_some() || login.is_some() { | ||
| init.set_referrer_policy(web_sys::ReferrerPolicy::NoReferrer); | ||
| init.set_credentials(web_sys::RequestCredentials::Omit); | ||
| } | ||
| Ok((window, request.to_string(), init, abort, range, tail, max, prepared.url, bound.to_string(), authenticated)) | ||
| Ok((window, normalized.href(), init, abort, range, tail, max, destination, bound.to_string(), authenticated)) | ||
| }, | ||
| |(window, request, init, abort, range, tail, max, url, bound, authenticated)| { | ||
| (window.fetch_with_str_and_init(&request, &init), abort, range, tail, max, url, bound, authenticated) | ||
|
|
@@ -704,6 +721,7 @@ async fn fetch_bytes( | |
| .dyn_into() | ||
| .map_err(err)?; | ||
| diagnostics.answered(resp.status()); | ||
| check_redirect(&resp)?; | ||
| if !resp.ok() { | ||
| return Err(refused(&resp)); | ||
| } | ||
|
|
@@ -771,12 +789,12 @@ async fn fetch_bytes( | |
| if whole_tail.is_some_and(|n| bytes.len() as u64 > n) { | ||
| return Err(format!("{url}: {}", cache::NO_RANGES)); | ||
| } | ||
| Ok(bytes) | ||
| Ok(cache::Fetched { bytes, origin: address::Origin::named(&url).retain_binding(&bound)? }) | ||
| } | ||
| .await; | ||
| cache::check_still(&still)?; | ||
| logins::check(&bound).map_err(str::to_string)?; | ||
| result.map_err(|error| if authenticated { logins::scrub_error(&format!("{url}: {error}")) } else { error }) | ||
| result.map_err(|error| crate::request::fetch_error(&url, error, authenticated)) | ||
| } | ||
| .await; | ||
| diagnostics.record(answer.map_err(|e| Failure::new(url, e))).map_err(|failure| failure.message) | ||
|
|
@@ -793,7 +811,7 @@ async fn post_json( | |
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::{cache::RequestDiagnostics, failure::Failure}; | ||
| let mut diagnostics = RequestDiagnostics::with_capture(url, "POST", capture); | ||
| let answer = async { | ||
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::{cache, logins, s3}; | ||
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::{address, cache, logins, s3}; | ||
| let (promise, authenticated) = crate::request::prepare_and_send( | ||
| &still, | ||
| || async { | ||
|
|
@@ -807,6 +825,7 @@ async fn post_json( | |
| let target = logins::inherit(url, &prepared.url); | ||
| let login = logins::apply(&target).map_err(str::to_string)?; | ||
| let request = prepared.url.as_str(); | ||
| check_destination(request, address::Reach::Local)?; | ||
| let err = |e: wasm_bindgen::JsValue| { | ||
| if login.is_some() { "the browser couldn't process the authenticated request".to_string() } else { format!("{e:?}") } | ||
| }; | ||
|
|
@@ -857,7 +876,7 @@ async fn post_json( | |
| .await; | ||
| cache::check_still(&still)?; | ||
| logins::check(url).map_err(str::to_string)?; | ||
| result.map_err(|error| if authenticated { logins::scrub_error(&format!("{url}: {error}")) } else { error }) | ||
| result.map_err(|error| crate::request::fetch_error(url, error, authenticated)) | ||
| } | ||
| .await; | ||
| diagnostics.record(answer.map_err(|e| Failure::new(url, e))).map_err(|failure| failure.message) | ||
|
|
@@ -874,7 +893,7 @@ async fn head( | |
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::{cache::RequestDiagnostics, failure::Failure}; | ||
| let mut diagnostics = RequestDiagnostics::with_capture(url, "HEAD", capture); | ||
| let answer = async { | ||
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::{cache, logins, s3}; | ||
| use rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::{address, cache, logins, s3}; | ||
| let sent = crate::request::prepare_and_send( | ||
| &still, | ||
| || async { | ||
|
|
@@ -887,6 +906,7 @@ async fn head( | |
| return Ok(None); | ||
| } | ||
| let url = prepared.url.as_str(); | ||
| check_destination(url, address::Reach::Local)?; | ||
| let target = logins::inherit(bound, url); | ||
| let login = logins::apply(&target).map_err(str::to_string)?; | ||
| let request = login.as_ref().map_or(url, |applied| applied.url.as_str()); | ||
|
|
@@ -895,6 +915,7 @@ async fn head( | |
| }; | ||
| let init = web_sys::RequestInit::new(); | ||
| init.set_method("HEAD"); | ||
| init.set_redirect(if login.is_some() { web_sys::RequestRedirect::Error } else { web_sys::RequestRedirect::Manual }); | ||
| let login_header = login.as_ref().and_then(|applied| applied.header.as_ref()); | ||
| if !prepared.headers.is_empty() || login_header.is_some() { | ||
| let headers = web_sys::Headers::new().map_err(err)?; | ||
|
|
@@ -909,7 +930,6 @@ async fn head( | |
| init.set_headers(&headers); | ||
| } | ||
| if login.is_some() { | ||
| init.set_redirect(web_sys::RequestRedirect::Error); | ||
| init.set_referrer_policy(web_sys::ReferrerPolicy::NoReferrer); | ||
| init.set_credentials(web_sys::RequestCredentials::Omit); | ||
| } | ||
|
|
@@ -933,6 +953,7 @@ async fn head( | |
| .dyn_into() | ||
| .map_err(err)?; | ||
| diagnostics.answered(resp.status()); | ||
| check_redirect(&resp)?; | ||
| if !resp.ok() { | ||
| return Err(refused(&resp)); | ||
| } | ||
|
|
@@ -947,12 +968,29 @@ async fn head( | |
| .await; | ||
| cache::check_still(&still)?; | ||
| logins::check(url).map_err(str::to_string)?; | ||
| result.map_err(|error| if authenticated { logins::scrub_error(&format!("{reached}: {error}")) } else { error }) | ||
| result.map_err(|error| crate::request::fetch_error(&reached, error, authenticated)) | ||
| } | ||
| .await; | ||
| diagnostics.record(answer.map_err(|e| Failure::new(url, e))).map_err(|failure| failure.message) | ||
| } | ||
|
|
||
| /// Checks the URL as the browser parses it, before any request or login renewal is sent. | ||
| fn check_destination(url: &str, ceiling: rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::address::Reach) -> Result<String, String> { | ||
| crate::request::destination(url, ceiling, |url| { | ||
| web_sys::Url::new(url).map(|normalized| normalized.href()).map_err(|_| "not a valid request address".into()) | ||
| }) | ||
| } | ||
|
|
||
| /// A manual redirect is an opaque, zero-status response: Fetch exposes no Location to check. | ||
| /// Other zero-status responses are unusable too; none is treated as a successful download. | ||
| fn check_redirect(response: &web_sys::Response) -> Result<(), String> { | ||
| if response.status() == 0 { | ||
| Err(rustgis_ui_egui::tl!("The browser cannot verify this redirect's destination. Use the final service address.").into()) | ||
| } else { | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| /// Makes an HTTP request (the AI assistant's calls to its model), returning the response of any | ||
| /// status. | ||
| async fn http( | ||
|
|
@@ -1023,9 +1061,9 @@ fn clipboard() -> Option<web_sys::Clipboard> { | |
| /// the app must not read what the user saved on the site. | ||
| fn services(inbox: Inbox, font_inbox: Inbox, notes: Notes, ctx: egui::Context, embedded: bool) -> Services { | ||
| // Map tiles come through the browser's fetch (the app repaints when they arrive). | ||
| rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::cache::set_fetcher_omitting(|url, done, omit| { | ||
| rustgis_ui_egui::rustgis_engine::render::rustgis_tiles::cache::set_fetcher_with_origin(|url, ceiling, done, omit| { | ||
| wasm_bindgen_futures::spawn_local(crate::request::handoff( | ||
| move |capture, still| async move { fetch_bytes(&url, capture, still, omit).await }, | ||
| move |capture, still| async move { fetch_reached(&url, ceiling, capture, still, omit).await }, | ||
| done, | ||
| )); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security (medium-low confidence, ~45%): a refusal here can echo the credential.
requestisarcgis.unwrap_or(login_url), andwith_token/login.applyappend the session token or login credential as a query parameter.check_reach(&normalized.href(), ceiling)then formats"{url}: …"with that full href. The?returns this error out ofprepare_and_sendand skipsfetch_error, so it reachescacheasState::Failedand then the drawing notices unscrubbed. History records are masked byredact(), but the returned string is not.The credential-free address was already judged at line 633, and the token only adds a query parameter, so judging the credential-free
urlkeeps the boundary without echoing the token:Confidence is moderate because the leak needs an authenticated request whose destination normalizes to a local or forbidden address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The earlier
check_destination(url, ceiling)already checksUrl::new(url).href()throughrequest::destination, before renewal or credential attachment. An escaped host that normalizes to a refused destination exits there. Service logins currently add a header; the session-token helper appends an encoded query value without changing the origin.I checked 18 cases using actual browser normalization and the production request/address helpers: 13 refusals occurred before credential attachment and five permitted controls passed. Skipping the earlier check made the same probe detect the synthetic credential in the error. No network requests were sent. I could not reproduce the reported leak on 404d4ad7.