Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(audit-P1): mount /favicon.ico at host root, outside base-path + auth

AkitaOnRails390ee790e42a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b2a25930..6db54519 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
+### Fixed
+- `GET /favicon.ico` now lives at the absolute host root, outside
+ `--base-path` and outside the `/web` nest, so the browser's
+ automatic favicon fetch actually reaches it. The 0.12.0 build mounted
+ the route inside the web router and ended up serving the icon only
+ at `/web/favicon.ico` — invisible to the browser's auto-fetch (the
+ icon still appeared via the in-page `<link rel="icon">` tag, so the
+ user-visible behaviour stayed correct, but the dedicated route was
+ unreachable). The new mount is also exempt from bearer auth and the
+ host allowlist so a fresh tab gets the icon without an HTTP Basic
+ prompt; the embedded PNG is the same one any visitor to `/web`
+ already sees, so the info-leak surface is nil. Surfaced by the
+ post-merge audit live test ([#79]).
## [0.12.0] - 2026-06-07
### Added
diff --git a/crates/ai-memory-cli/src/commands/serve.rs b/crates/ai-memory-cli/src/commands/serve.rs
index 117714f8..b08014dd 100644
--- a/crates/ai-memory-cli/src/commands/serve.rs
+++ b/crates/ai-memory-cli/src/commands/serve.rs
@@ -339,6 +339,18 @@ pub async fn run(config: &Config, args: ServeArgs) -> Result<()> {
} else {
axum::Router::new().nest(&base_path, router)
};
+ // Mount `/favicon.ico` at the absolute HOST root — outside the
+ // auth gate, outside `--base-path`, outside the `/web` nest.
+ // Browsers auto-fetch `<host>/favicon.ico` without auth headers
+ // regardless of where the app is mounted; routing it under
+ // `/web` (as PR #79 originally did) made it unreachable to the
+ // browser's automatic fetch. Negligible info leak — the icon
+ // is the same embedded PNG anyone hitting `/web` already sees.
+ let router = if args.enable_web {
+ router.merge(ai_memory_web::favicon_router())
+ } else {
+ router
+ };
let listener = tokio::net::TcpListener::bind(&bind)
.await
.with_context(|| format!("binding {bind}"))?;
@@ -1459,6 +1471,9 @@ mod tests {
} else {
axum::Router::new().nest(&base, router)
};
+ // Mirror the production favicon mount in serve handler: at the
+ // absolute host root, outside the base-path nest.
+ let router = router.merge(ai_memory_web::favicon_router());
(tmp, router)
}
@@ -1651,6 +1666,43 @@ mod tests {
);
}
+ /// Post-merge audit (Phase 7 live test) caught that PR #79's
+ /// `/favicon.ico` route was nested inside `/web`, so it lived at
+ /// `/web/favicon.ico` and the browser's automatic root fetch always
+ /// 404'd. Fix: a separate `favicon_router()` mounted at the absolute
+ /// HOST root, outside `--base-path` and outside the `/web` nest.
+ /// This test pins both:
+ /// * `/favicon.ico` at the host root returns the PNG.
+ /// * Under `--base-path /wiki`, the favicon STAYS at root —
+ /// browsers fetch `<host>/favicon.ico` regardless of where the
+ /// app is mounted; the route must not move with the prefix.
+ #[tokio::test]
+ async fn favicon_lives_at_host_root_regardless_of_base_path() {
+ for base_path in ["", "/wiki"] {
+ let (_tmp, router) = based_web_router(base_path, "/web");
+ let resp = router
+ .oneshot(
+ Request::builder()
+ .uri("/favicon.ico")
+ .body(Body::empty())
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ resp.status(),
+ StatusCode::OK,
+ "/favicon.ico must be reachable at host root (base_path={base_path:?})"
+ );
+ assert_eq!(
+ resp.headers()
+ .get(axum::http::header::CONTENT_TYPE)
+ .and_then(|v| v.to_str().ok()),
+ Some("image/png"),
+ );
+ }
+ }
+
#[tokio::test]
async fn no_base_path_is_byte_equivalent_at_root() {
let (_tmp, router) = based_web_router("", "/web");
diff --git a/crates/ai-memory-web/src/lib.rs b/crates/ai-memory-web/src/lib.rs
index 7e98f37e..f0896893 100644
--- a/crates/ai-memory-web/src/lib.rs
+++ b/crates/ai-memory-web/src/lib.rs
@@ -51,3 +51,11 @@ pub fn api_router(reader: ReaderPool, wiki: Wiki) -> Router {
let state = Arc::new(WebState::new(reader, wiki));
routes::build_api(state)
}
+
+/// Standalone `GET /favicon.ico` router. Merge at the host-root level
+/// (NOT under `--base-path`, NOT nested under `/web`) so the browser's
+/// automatic `/favicon.ico` fetch actually reaches it. The handler is
+/// stateless — it returns the same embedded PNG as `/web/static/logo.png`.
+pub fn favicon_router() -> Router {
+ routes::build_favicon()
+}
diff --git a/crates/ai-memory-web/src/routes/mod.rs b/crates/ai-memory-web/src/routes/mod.rs
index 608c7a3b..9f0ab677 100644
--- a/crates/ai-memory-web/src/routes/mod.rs
+++ b/crates/ai-memory-web/src/routes/mod.rs
@@ -23,7 +23,6 @@ pub(crate) fn build(state: Arc<WebState>) -> Router {
.route("/search", get(search::handler))
.route("/static/tailwind.css", get(statics::tailwind_css))
.route("/static/logo.png", get(statics::logo))
- .route("/favicon.ico", get(statics::favicon))
.with_state(state)
}
@@ -31,3 +30,15 @@ pub(crate) fn build(state: Arc<WebState>) -> Router {
pub(crate) fn build_api(state: Arc<WebState>) -> Router {
api::build(state)
}
+
+/// Standalone `GET /favicon.ico` router. Mounted at the **host root**
+/// by `serve`, OUTSIDE the `/web` nest and OUTSIDE the `--base-path`
+/// prefix, because browsers auto-fetch `/favicon.ico` from the host
+/// origin regardless of where the rest of the app is mounted. Putting
+/// it inside the web router (as the original PR #79 did) made it
+/// reachable only at `/web/favicon.ico` — never seen by the browser's
+/// automatic fetch — so the in-page `<link rel="icon">` was the only
+/// thing actually showing the icon.
+pub(crate) fn build_favicon() -> Router {
+ Router::new().route("/favicon.ico", get(statics::favicon))
+}
diff --git a/docs/frontend-api.md b/docs/frontend-api.md
index 69c4127b..52e79593 100644
--- a/docs/frontend-api.md
+++ b/docs/frontend-api.md
@@ -367,12 +367,15 @@ GET /favicon.ico
Returns the same transparent PNG the built-in web UI serves as the
header logo. Browsers fetch this path automatically. The route is
-present whenever the web UI is enabled (`--enable-web`); the response
-is `image/png` despite the `.ico` URL — modern browsers accept PNG
-icons. Bearer auth applies as it does to `/web/*`: in a browser the
-favicon request rides the same HTTP Basic credentials the user
-pasted to load `/web`, so the icon appears once the session is
-authenticated.
+present whenever the web UI is enabled (`--enable-web`) and is
+mounted at the absolute host root — outside `--base-path` and outside
+the `/web` nest — so the browser's automatic fetch reaches it even
+under a subpath deployment. The response is `image/png` despite the
+`.ico` URL (modern browsers accept PNG icons), and the route is
+**exempt from bearer auth and host allowlist**: a browser opening a
+fresh tab gets the icon without an HTTP Basic prompt, and the
+embedded PNG is the same one any visitor to `/web` already sees, so
+the info-leak surface is nil.
## 5. Limits and pagination