Skip to content

Apply the FAB login rate limit to the API login endpoints - #77931

Open
ChickenBenny wants to merge 3 commits into
apache:mainfrom
ChickenBenny:fab-rate-limit-api-login
Open

ChickenBenny wants to merge 3 commits into
apache:mainfrom
ChickenBenny:fab-rate-limit-api-login

Conversation

@ChickenBenny

Copy link
Copy Markdown
Contributor

[fab] auth_rate_limit (5 requests per 40 seconds by default) is applied only to the Flask login form.
The other endpoints that take a username and password have no limit: POST /auth/token,
POST /auth/token/cli and the Flask-AppBuilder security API login (POST /auth/api/v1/security/login).
The FAB docs and the config descriptions say that authentication requests are rate limited, so a password
guess sent to these endpoints is not slowed down although the docs say it is.

The Airflow security team assessed this as hardening, not a vulnerability: rate limiting is the Deployment
Manager's job under the Security Model, and the FAB limiter is a convenience. They suggested fixing it in a
public PR.

  • Token endpoints. Flask-Limiter only limits Flask views, so the security manager's new
    check_api_login_rate_limit counts each attempt directly in the Flask-Limiter storage, with the same
    [fab] auth_rate_limit. Both token endpoints share one counter per client address and return 429 when it
    is reached. They use the configured storage and RATELIMIT_SWALLOW_ERRORS, so with an unreachable storage
    they fail, or let the login through when errors are swallowed, as the login form does. The in-memory
    fallback storage, RATELIMIT_KEY_FUNC and RATELIMIT_KEY_PREFIX only work inside Flask-Limiter's request
    handling, so they do not apply to the token endpoints, and the docs say so.
  • Security API. Only its login endpoint is limited. refresh takes a refresh token, not a password, and
    limiting it would change what clients that refresh often get today.
  • One place for the login limits. The login form and the security API now go through the same
    _rate_limit_logins helper in the security manager, and the token routes only call
    check_api_login_rate_limit.
  • Docs. The "Rate limiting" section lists the three endpoints that are limited and their counters,
    replaces the old gunicorn worker example with [api] workers, lists which RATELIMIT_* settings apply to
    the token endpoints, notes that the API server needs --proxy-headers behind a proxy, and links the
    Security Model.
  • Dependency. limits was already installed through flask-limiter. It is now declared, since the
    security manager imports it.

The three counters (login form, token endpoints, security API login) stay separate. Sharing one with the
login form would mean building Flask-Limiter's internal keys (prefix, key and scope) by hand for the token
endpoints, which would break when Flask-Limiter changes them.

Tests: with the default limit, the two token endpoints return 401 five times and then 429, alternating
between them, and so does the security API login, while its refresh is not limited. With
AUTH_RATE_LIMITED off, or the limiter disabled, the token endpoints are not limited. A storage error fails the token request, or
is logged and ignored with RATELIMIT_SWALLOW_ERRORS.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 5.5)

Generated-by: Claude Code (Opus 5.5) following the guidelines

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant