Skip to content

Global rate_limit config is documented and parsed but never read — enabling it does nothing #127

Closed

Description

@jrosskopf

What

RateLimitMiddleware::before_handle resolves the limit only from the endpoint:

const auto endpoint = config_manager->getEndpointForPath(req.url);
if (!endpoint || !endpoint->rate_limit.enabled) {
    return;
}

The global rate_limit: block is parsed into ConfigManager::rate_limit_config and read by nothing:

$ grep -rn "getRateLimitConfig\|rate_limit_config" src/ --include=*.cpp --include=*.hpp \
    | grep -v config_manager
(no output)

Meanwhile four keys are documented in docs/CONFIG_REFERENCE.md:500-503 — rate_limit.enabled, .max, .interval, .key — described as "Enable rate limiting globally".

Measured

Server with a global limit of 2 per 60s and no per-endpoint rate-limit::

request 1: 200   {"data":[...]}
request 2: 200   {"data":[...]}
request 3: 200   {"data":[...]}     <-- no limit applied
request 4: 200   {"data":[...]}

With the same numbers moved into the endpoint's own rate-limit: block, request 3 is refused. So the feature works per-endpoint and is inert globally.

Why it matters

An operator who configures global rate limiting — the documented way to protect a whole deployment — gets no rate limiting at all, with no warning at startup and no error. They believe they are protected and are not.

This is the exact failure mode CLAUDE.md's documentation checklist calls out: "Every config key you document, grep for a reader in src/, not just a parser. Three keys once shipped documented and parsed but never read; operators could set them and nothing happened."

Suggested fix

Fall back to the global config when an endpoint declares no rate-limit: of its own, so per-endpoint overrides global. That is what the documentation already promises.

Not fixed in passing: making it live means deployments that set the global block — and are currently unlimited — start returning 429s. That is a real behaviour change and needs an owner decision, plus a release note. The alternative is to delete the keys and the docs, which is worse: the global option is the one that should exist.

Found during an architecture review round on the request hot path, while verifying #127.

Activity

  1. jrosskopf commented on Sep 22, 2026

    @jrosskopf
    ContributorAuthor

    Fixed in #135 (merged as 23bd0f0).

    The global rate_limit: block now applies to endpoints that declare no rate-limit: of their own. Per-endpoint config still wins.

    Behaviour change: deployments that set the global block and are unlimited today will start returning 429s — the documented behaviour finally happening.

    A crew review of that change caught a second defect before it merged: rate-limit: {enabled: false} could not opt out, because an explicit off was indistinguishable from "never declared" (both leave enabled false). RateLimitConfig gained a declared flag, and the middleware treats declared || enabled as endpoint ownership so a config built in code still behaves.

    Covered by test_rate_limit_enforcement.py: the global block applies, a per-endpoint block overrides it (both configured and different, which the first version of that test failed to do), and an explicit opt-out is honoured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions