Summary
cortex-app-server defines production middleware for rate limiting, request timeouts, security headers, and content-type validation, but create_router_with_state() never attaches those middleware layers to the Axum router. As a result, enabling rate_limit in ServerConfig does not actually protect the API routes, and the implemented timeout/security-header/content-type middleware is also dead code for normal requests.
Evidence

The relevant code paths are:
src/cortex-app-server/src/middleware.rs:109 defines rate_limit_middleware.
src/cortex-app-server/src/middleware.rs:186 defines timeout_middleware.
src/cortex-app-server/src/middleware.rs:203 defines security_headers_middleware.
src/cortex-app-server/src/middleware.rs:226 defines content_type_middleware.
src/cortex-app-server/src/lib.rs:142-143 only attaches TraceLayer::new_for_http() and CorsLayer::permissive().
Command used to verify the mismatch:
rg -n 'rate_limit_middleware|timeout_middleware|security_headers_middleware|content_type_middleware|auth_middleware|\.layer\(' \
src/cortex-app-server/src/lib.rs \
src/cortex-app-server/src/middleware.rs \
src/cortex-app-server/src/auth.rs
The output shows the middleware functions exist, but the router only applies Trace and CORS layers.
Expected behavior
When config.rate_limit.enabled is true, requests should pass through rate_limit_middleware. The timeout, security headers, and content-type validation middleware should also be attached if they are intended to protect app-server API routes.
Actual behavior
create_router_with_state() builds the router and attaches only:
.layer(TraceLayer::new_for_http())
.layer(CorsLayer::permissive())
No rate-limit, timeout, content-type, or security-header middleware is applied to /api/v1 routes.
Impact
Operators can enable rate limiting in config and believe the API is protected, but the configured limiter is never enforced. This also leaves the implemented timeout, content-type, and security-header protections inactive on normal HTTP API requests.
Summary
cortex-app-serverdefines production middleware for rate limiting, request timeouts, security headers, and content-type validation, butcreate_router_with_state()never attaches those middleware layers to the Axum router. As a result, enablingrate_limitinServerConfigdoes not actually protect the API routes, and the implemented timeout/security-header/content-type middleware is also dead code for normal requests.Evidence
The relevant code paths are:
src/cortex-app-server/src/middleware.rs:109definesrate_limit_middleware.src/cortex-app-server/src/middleware.rs:186definestimeout_middleware.src/cortex-app-server/src/middleware.rs:203definessecurity_headers_middleware.src/cortex-app-server/src/middleware.rs:226definescontent_type_middleware.src/cortex-app-server/src/lib.rs:142-143only attachesTraceLayer::new_for_http()andCorsLayer::permissive().Command used to verify the mismatch:
rg -n 'rate_limit_middleware|timeout_middleware|security_headers_middleware|content_type_middleware|auth_middleware|\.layer\(' \ src/cortex-app-server/src/lib.rs \ src/cortex-app-server/src/middleware.rs \ src/cortex-app-server/src/auth.rsThe output shows the middleware functions exist, but the router only applies Trace and CORS layers.
Expected behavior
When
config.rate_limit.enabledis true, requests should pass throughrate_limit_middleware. The timeout, security headers, and content-type validation middleware should also be attached if they are intended to protect app-server API routes.Actual behavior
create_router_with_state()builds the router and attaches only:No rate-limit, timeout, content-type, or security-header middleware is applied to
/api/v1routes.Impact
Operators can enable rate limiting in config and believe the API is protected, but the configured limiter is never enforced. This also leaves the implemented timeout, content-type, and security-header protections inactive on normal HTTP API requests.