From 255faf0e4c9801936f937c57045851f5c314150b Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Mon, 24 Aug 2026 12:28:42 +0000 Subject: [PATCH] fix(elasticsearch): support OpenSearch Dashboards proxy XSRF Closes #7075 --- crates/dbx-core/src/db/elasticsearch_driver.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/dbx-core/src/db/elasticsearch_driver.rs b/crates/dbx-core/src/db/elasticsearch_driver.rs index 7a48f3016c..035009fc1f 100644 --- a/crates/dbx-core/src/db/elasticsearch_driver.rs +++ b/crates/dbx-core/src/db/elasticsearch_driver.rs @@ -170,7 +170,8 @@ impl EsClient { .http .post(format!("{}/api/console/proxy", self.base_url)) .query(&[("path", path), ("method", method.as_str())]) - .header("kbn-xsrf", "true"), + .header("kbn-xsrf", "true") + .header("osd-xsrf", "true"), }; self.with_auth(req) } @@ -3358,6 +3359,7 @@ mod tests { assert_eq!(query.get("path").map(String::as_str), Some("/missing/_doc/1?refresh=true")); assert_eq!(query.get("method").map(String::as_str), Some("DELETE")); assert!(headers.lines().any(|line| line.eq_ignore_ascii_case("kbn-xsrf: true")), "{headers}"); + assert!(headers.lines().any(|line| line.eq_ignore_ascii_case("osd-xsrf: true")), "{headers}"); assert!(headers.lines().any(|line| line.eq_ignore_ascii_case("authorization: Basic ZWxhc3RpYzpzZWNyZXQ="))); assert_eq!(serde_json::from_str::(body).unwrap(), json!({ "reason": "cleanup" })); @@ -3389,6 +3391,15 @@ mod tests { assert_eq!(result.rows[0][1], json!(response_body)); } + #[test] + fn direct_transport_omits_proxy_xsrf_headers() { + let client = EsClient::new("http://localhost:9200", None, None, false, Duration::from_secs(1)); + let request = client.get("/").build().unwrap(); + + assert!(!request.headers().contains_key("kbn-xsrf")); + assert!(!request.headers().contains_key("osd-xsrf")); + } + #[tokio::test] async fn execute_rest_query_sends_encoded_date_math_path() { use tokio::io::AsyncWriteExt;