AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(console): dashboard panels never authenticate to the data plane (#142)
Vinz21686cbc30f815c3
diff --git a/engine/crates/xerj-console-api/src/data_sources.rs b/engine/crates/xerj-console-api/src/data_sources.rsindex aad1be978..a4223818d 100644--- a/engine/crates/xerj-console-api/src/data_sources.rs+++ b/engine/crates/xerj-console-api/src/data_sources.rs@@ -21,7 +21,8 @@use axum::{extract::{Path, State},- response::Response,+ response::{IntoResponse, Response},+ Json,};use serde::Serialize;use serde_json::{json, Value};@@ -189,6 +190,94 @@ pub async fn list_fields(Ok(ok(json!({ "fields": fields, "total": fields.len() }), None))}+// ─────────────────────────────────────────────────────────────────────────────+// SEARCH+// ─────────────────────────────────────────────────────────────────────────────++/// Run an ES-compat `_search` against a single index, authenticated by the+/// caller's Console session instead of a data-plane API key.+///+/// **Why this exists.** The SPA's declarative dashboard panels+/// (`xerj-ux/src/data/panel-query.js`) and the built-in dashboard adapters+/// (`xerj-ux/src/data/backends/xerj.js`) used to `fetch()` `/{index}/_search`+/// directly, same-origin, with no `Authorization` header at all. That is+/// silently correct only when the engine is started with `--insecure`; on+/// any auth-enabled deployment — the default, recommended posture — every+/// such call gets a 401 the caller doesn't even look at (`backends/xerj.js`+/// treats any failure as "no live adapter, fall back to mock"), so the+/// entire "real dashboards" feature quietly regresses to demo data with no+/// visible error. This endpoint reuses the session-cookie gate every other+/// `data-sources` route already has (see `list_indices` / `list_fields`+/// above) and talks to the engine in-process — no data-plane credential is+/// needed at all, the same way `list_indices`/`list_fields` already read+/// the schema/stats in-process.+///+/// **Scope.** Single, exact index names only, matching `list_fields`'s+/// existing scope — no wildcard/`_all` resolution or multi-index merge+/// here (that logic is non-trivial and already lives, correctly, in+/// `xerj-api::es_compat`; duplicating a second copy risks exactly the kind+/// of subtle merge bug that logic has already been hardened against).+/// Callers that need a pattern get a clear `501`, not a silent wrong+/// answer — consistent with how this file already treats non-`built-in`+/// connections.+pub async fn search(+ State(state): State<ConsoleState>,+ _sess: AuthSession,+ Path((conn_id, index)): Path<(String, String)>,+ Json(body): Json<Value>,+) -> ConsoleResult<Response> {+ if conn_id != BUILTIN_ID {+ return Err(ConsoleApiError::NotImplemented(format!(+ "connection '{conn_id}' adapter not yet implemented"+ )));+ }+ if index.contains('*') || index == "_all" || index.split(',').count() > 1 {+ return Err(ConsoleApiError::NotImplemented(+ "panel search proxy supports a single exact index name only; \+ wildcard/_all/multi-index queries are not yet implemented"+ .into(),+ ));+ }+ if indices::is_system_index(&index) {+ return Err(ConsoleApiError::NotFound(format!("index {index}")));+ }+ let idx = state+ .engine+ .get_index(&index)+ .map_err(|_| ConsoleApiError::NotFound(format!("index {index}")))?;++ let req = xerj_query::parser::parse_request(&body)+ .map_err(|e| ConsoleApiError::BadRequest(e.to_string()))?;+ let result = idx+ .search(&req)+ .await+ .map_err(|e| ConsoleApiError::Internal(e.to_string()))?;++ let hits: Vec<Value> = result+ .hits+ .iter()+ .map(|h| {+ json!({+ "_index": index,+ "_id": h.id,+ "_score": h.score,+ "_source": h.source,+ })+ })+ .collect();+ let wire = json!({+ "took": result.took_ms,+ "timed_out": result.timed_out,+ "hits": {+ "total": { "value": result.total.value, "relation": result.total.relation },+ "max_score": result.max_score,+ "hits": hits,+ },+ "aggregations": result.aggs,+ });+ Ok(Json(wire).into_response())+}+// ─────────────────────────────────────────────────────────────────────────────// Built-in auto-provisioning// ─────────────────────────────────────────────────────────────────────────────diff --git a/engine/crates/xerj-console-api/src/router.rs b/engine/crates/xerj-console-api/src/router.rsindex c54b6d7b7..a9d1a01d9 100644--- a/engine/crates/xerj-console-api/src/router.rs+++ b/engine/crates/xerj-console-api/src/router.rs@@ -140,6 +140,10 @@ pub fn xerj_console_router(state: ConsoleState) -> Router {"/_xerj-console/api/v1/data-sources/connections/:id/indices/:name/fields",get(data_sources::list_fields),)+ .route(+ "/_xerj-console/api/v1/data-sources/connections/:id/indices/:name/search",+ post(data_sources::search),+ ).with_state(state)}@@ -173,5 +177,6 @@ pub fn known_routes() -> &'static [&'static str] {"/_xerj-console/api/v1/data-sources/connections","/_xerj-console/api/v1/data-sources/connections/:id/indices","/_xerj-console/api/v1/data-sources/connections/:id/indices/:name/fields",+ "/_xerj-console/api/v1/data-sources/connections/:id/indices/:name/search",]}diff --git a/xerj-ux/src/data/backends/xerj.js b/xerj-ux/src/data/backends/xerj.jsindex 98ec29c60..bdb6bea30 100644--- a/xerj-ux/src/data/backends/xerj.js+++ b/xerj-ux/src/data/backends/xerj.js@@ -64,11 +64,31 @@ export async function listIndices(baseUrl, signal) {return r.json().catch(() => []);}-/** Generic ES-compat search against a single index (or wildcard). */+/**+ * Search a single index through the Console backend's session-authenticated+ * proxy instead of an unauthenticated same-origin fetch straight to the+ * ES-compat data plane. The old direct call carried no `Authorization`+ * header, so it silently 401'd on any engine started WITHOUT `--insecure`+ * — the default, recommended posture — and every caller here treats a+ * failed search as "no live adapter, fall back to mock" (see `search()`+ * below), so the built-in dashboards quietly showed demo data on a+ * correctly-secured deployment with no visible error at all.+ *+ * `baseUrl` is intentionally unused for the request target: the proxy is+ * always served by the SAME Console instance the SPA is loaded from (this+ * backend only ever talks to the local/built-in engine — see `meta`+ * above), so the path is resolved relative to the current origin, same as+ * every other Console-backend call in this codebase. Kept as a parameter+ * for call-site compatibility.+ *+ * Scope: single exact index name only — no wildcard/`_all` resolution.+ * See `xerj-console-api::data_sources::search`'s doc comment for why.+ */async function rawSearch(baseUrl, index, body, signal) {- const path = `/${encodeURIComponent(index)}/_search`;- const r = await fetch(baseUrl + path, {+ const path = `/_xerj-console/api/v1/data-sources/connections/built-in/indices/${encodeURIComponent(index)}/search`;+ const r = await fetch(path, {method: 'POST',+ credentials: 'same-origin',headers: { 'content-type': 'application/json' },body: JSON.stringify(body),signal,diff --git a/xerj-ux/src/data/panel-query.js b/xerj-ux/src/data/panel-query.jsindex e983acae1..ac93fca20 100644--- a/xerj-ux/src/data/panel-query.js+++ b/xerj-ux/src/data/panel-query.js@@ -154,8 +154,18 @@ function normalise(resp, built) {return out;}+// Routed through the Console backend's own session-cookie auth instead of+// a same-origin fetch straight to the ES-compat data plane. That direct+// path carried no `Authorization` header at all, so it silently 401'd on+// any engine started WITHOUT `--insecure` — the default, recommended+// posture — leaving every custom panel stuck on "unconfigured"/error with+// no indication why. The proxy runs the search in-process against the+// engine, authenticated the same way `data-sources/connections/.../fields`+// already is. See `xerj-console-api::data_sources::search` for the+// server side and its scope note (single exact index name only, no+// wildcard/`_all` yet).async function runQuery(built, signal) {- const path = `/${encodeURIComponent(built.index)}/_search`;+ const path = `/_xerj-console/api/v1/data-sources/connections/built-in/indices/${encodeURIComponent(built.index)}/search`;const r = await fetch(path, {method: 'POST',credentials: 'same-origin',