# Rate Limit Password Reset in a Flask App from a Linear Issue

An agent caps password reset requests at 3 per email per hour with Flask-Limiter, answers the fourth with 429 and a message, and pytest passes.

[Run this on Rush](https://cloud.getrush.ai/run/add-password-reset-rate-limit/flask/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads `app/auth/routes.py`, `app/__init__.py`, `config.py`, `requirements.txt`, the `auth/reset_password_request.html` template and `tests.py` first. The app had no rate limiting, already pinned every dependency, and already had a Redis URL in `Config`.

It creates one `Limiter` in `app/__init__.py` and decorates `reset_password_request` with `@limiter.limit('3 per hour', key_func=reset_request_key, methods=['POST'], on_breach=reset_request_limited)`. The key is the submitted email, trimmed and lowercased, with the client address only when no email is sent. On a breach it re-renders the reset form with a flash message and status 429. `config.py` gets `RATELIMIT_STORAGE_URI`, defaulting to `memory://`, and `tests.py` gets a `PasswordResetRateLimitCase` with three tests.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "A Linear issue labeled agent says: \"Rate Limit Password Reset in a Flask App. Allow at most 3 reset password requests per email per hour with Flask-Limiter and show a friendly message when the limit is hit.\" Do the work in this repository, add tests for it, run pytest, and open a pull request that links back to the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on miguelgrinberg/microblog at a975ef6: 5 files changed, 78 insertions(+), 3 deletions(-) in `app/__init__.py`, `app/auth/routes.py`, `config.py`, `requirements.txt` and `tests.py`. `pytest tests.py` went from `4 passed in 2.08s` on the untouched clone to `7 passed in 1.47s`. The first test asserts that three POSTs return 302, the fourth 429 with `too many password resets`, and that only 3 mails were recorded. The Linear issue was the task text; the run had no issue id to link and opened no pull request.

For the reviewer: `memory://` is per process, so with several gunicorn workers the real limit is higher; decide whether to default to the existing `REDIS_URL`. The new message is not in the Spanish translations, and `uv` resolved the three new pins, `Flask-Limiter==4.1.1`, `limits==5.8.0` and `ordered-set==4.1.0`, so re-check them with pip.

## Run it on every Linear issue labeled agent

An automation with a `linear` trigger on `linear.issue.labeled` and the label `agent` runs the `linear-label-to-pr` recipe's prompt when someone in your Rush org labels a security issue. An issue that names the limiter storage, such as the app's existing `REDIS_URL`, lets the agent use it instead of the per-process `memory://` default.

## Why run it on Rush?

The first version of the new tests got 200 instead of 302: Flask-WTF's CSRF check rejected the test client's forms. The run found that, set `WTF_CSRF_ENABLED = False` in the test config, and checked the mail outbox, so the limit is proven to stop the fourth email and not just the fourth page.

## Frequently asked questions

### Does an unknown email count toward the limit?

Yes. Every POST with an address counts, registered or not, so the response never tells an attacker which emails exist. Someone can still send a victim up to 3 reset mails an hour.

### Why is GET not limited?

The decorator passes `methods=['POST']`, so viewing the form never uses up an attempt. `test_get_is_not_limited` sends four POSTs and then expects the form to load with 200.

## More Flask jobs

- [Add Rate Limiting to a Flask API](https://getrush.ai/run/add-rate-limiting/flask/)
- [Add Structured Logging to a Flask App](https://getrush.ai/run/add-structured-logging/flask/)
- [Add Type Hints to a Flask Codebase](https://getrush.ai/run/add-type-hints/flask/)

## More jobs like this: Turn a Linear label into a PR

- [Encrypt Temporal Workflow Payloads with a Custom Codec](https://getrush.ai/run/add-payload-encryption/temporal/)
- [Add PDF Invoices to a Filament Admin Panel from a Linear Issue](https://getrush.ai/run/add-pdf-invoices/filament/)
- [Add a Periodic Task with Celery Beat](https://getrush.ai/run/add-periodic-tasks/celery/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
