From ce7c8dbca1ca994ece1e139f9749d8aa4c780d66 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 13 Aug 2026 00:36:33 +0200 Subject: [PATCH] fix: send http requests in origin not absolute form Absolute form is meant for proxies and for example nginx rejects it with 400 if the host contains an underscore, breaking autoconfig discovery. --- .../src/deltachat_rpc_client/pytestplugin.py | 5 +--- deltachat-rpc-client/tests/test_cross_core.py | 4 +-- src/net/http.rs | 27 +++++++++++++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py index cad588048..635083457 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py @@ -363,10 +363,7 @@ def remote_bob_loop(channel): # ACFactory would configure from a "dcaccount" QR, # which old cores cannot use on underscore domains bob = dc.add_account() - bob.set_config_from_qr(dclogin_qr) - if not bob.is_configured(): - # cores <=2.22 only store login values from a "dclogin" QR - bob.configure() + bob.add_transport_from_qr(dclogin_qr) bob.bring_online() alice_vcard = channel.receive() diff --git a/deltachat-rpc-client/tests/test_cross_core.py b/deltachat-rpc-client/tests/test_cross_core.py index f58d1d23a..35424e22a 100644 --- a/deltachat-rpc-client/tests/test_cross_core.py +++ b/deltachat-rpc-client/tests/test_cross_core.py @@ -45,7 +45,7 @@ def test_qr_setup_contact(acfactory, alice_and_remote_bob, version) -> None: def test_send_and_receive_message(alice_and_remote_bob) -> None: """Test other-core Bob profile can send a message to Alice on current core.""" - alice, alice_contact_bob, remote_eval = alice_and_remote_bob("2.20.0") + alice, alice_contact_bob, remote_eval = alice_and_remote_bob("2.23.0") remote_eval("bob_contact_alice.create_chat().send_text('hello')") @@ -55,7 +55,7 @@ def test_send_and_receive_message(alice_and_remote_bob) -> None: def test_second_device(acfactory, alice_and_remote_bob) -> None: """Test setting up current version as a second device for old version.""" - _alice, alice_contact_bob, remote_eval = alice_and_remote_bob("2.20.0") + _alice, alice_contact_bob, remote_eval = alice_and_remote_bob("2.23.0") remote_eval("locals().setdefault('future', bob._rpc.provide_backup.future(bob.id))") qr = remote_eval("bob._rpc.get_backup_qr(bob.id)") diff --git a/src/net/http.rs b/src/net/http.rs index 7bb55ffc9..b1f980707 100644 --- a/src/net/http.rs +++ b/src/net/http.rs @@ -258,6 +258,15 @@ pub(crate) async fn http_cache_cleanup(context: &Context) -> Result<()> { Ok(()) } +/// Returns the request target in origin form, i.e. the path and query of `url`. +/// +/// The absolute form is only for proxy requests and +/// nginx rejects it if the host starts contains an underscore. +fn origin_form(url: &hyper::Uri) -> &str { + url.path_and_query() + .map_or("/", |path_and_query| path_and_query.as_str()) +} + /// Fetches URL and updates the cache. /// /// URL is fetched regardless of whether there is an existing result in the cache. @@ -276,7 +285,7 @@ async fn fetch_url(context: &Context, original_url: &str, strict_tls: bool) -> R .context("URL has no authority")? .clone(); - let req = hyper::Request::builder().uri(parsed_url); + let req = hyper::Request::builder().uri(origin_form(&parsed_url)); // OSM usage policy requires // that User-Agent is set for HTTP GET requests @@ -409,7 +418,7 @@ pub(crate) async fn post_empty(context: &Context, url: &str) -> Result<(String, .authority() .context("URL has no authority")? .clone(); - let req = hyper::Request::post(parsed_url) + let req = hyper::Request::post(origin_form(&parsed_url)) .header(hyper::header::HOST, authority.as_str()) .body(http_body_util::Empty::::new())?; @@ -432,6 +441,20 @@ mod tests { use crate::test_utils::TestContext; use crate::tools::SystemTime; + #[test] + fn test_origin_form() { + let url = "https://_cm0.localchat/autoconfig?emailaddress=x%40_cm0.localchat" + .parse() + .unwrap(); + assert_eq!( + origin_form(&url), + "/autoconfig?emailaddress=x%40_cm0.localchat" + ); + + let url = "https://example.org".parse().unwrap(); + assert_eq!(origin_form(&url), "/"); + } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_http_cache() -> Result<()> { let t = &TestContext::new().await;