Skip to content

[BUG] [v0.0.7] app-server rate_limit/timeout/security-header middlewares are defined but never attached to the router #53530

@DDDDDGCSM

Description

@DDDDDGCSM

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

middleware proof

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ideIssues related to IDEvalidValid issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions