Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(elasticsearch): support OpenSearch Dashboards proxy XSRF

t8y2255faf0e4c98
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::<serde_json::Value>(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;