Review application A.3.2
Security and rate limits
On this page
The review application is a public, read-only dashboard: it has no user accounts and stores no personal data. Its protections therefore aim at availability, so that no single client can exhaust the shared web workers or the database. This page describes the rate limits, the bounds on database work and the optional HTTPS redirect.
Rate limits
Flask-Limiter counts requests per client IP address (get_remote_address). Every route without its own limit allows 500 requests per minute (default_limits in backend/extensions.py). Expensive or easily abused routes are stricter:
| Endpoint(s) | Limit | Defined in |
|---|---|---|
/api/data |
60/minute | backend/blueprints/data.py |
/api/atlas_operators, /api/osm_operators, /api/osm_operator_wikidata, /api/osm_route_operators |
60/minute | backend/blueprints/data.py |
/api/stop_popup |
120/minute | backend/blueprints/data.py |
/api/top_matches, /api/stop_by_id, /api/lookup |
60/minute | backend/blueprints/search.py |
/api/search/suggest |
240/minute | backend/blueprints/search.py |
/api/random_stop |
30/minute | backend/blueprints/search.py |
/api/problems, /api/problems/stats |
120/minute | backend/blueprints/problems.py |
/api/global_stats |
30/minute | backend/blueprints/stats.py |
/api/system/pipeline_status |
120/minute | backend/blueprints/system.py |
/api/generate_report_async |
10/hour | backend/blueprints/reports.py |
/api/exports/<task_id>/progress, for every export |
240/minute | backend/blueprints/reports.py |
/api/exports/<task_id>/download |
20/minute | backend/blueprints/reports.py |
/api/exports/<task_id>/cancel |
60/minute | backend/blueprints/reports.py |
/api/docs/generate_pdf_async, which starts a documentation PDF, has no limit of its own and uses the default. A client over a limit receives HTTP 429 Too Many Requests.
Behind a reverse proxy, get_remote_address sees the proxy's address, so all visitors share one set of counters. The application does not read X-Forwarded-For. Either enforce limits at the proxy, or wrap the application in Werkzeug's ProxyFix with the exact number of trusted proxies; trusting the header without a proxy that overwrites it would let clients choose their own address.
Where the counters live
RATELIMIT_STORAGE_URI selects the counter store; the default is memory://. The rate-limit store is independent of the pipeline status, run lock and export progress, which are JSON files under STATE_DIR (data/runtime).
With memory://, each Gunicorn worker counts on its own. The production command starts two workers, so a client can make up to twice the stated number of requests:
Here the client made 80 requests in a minute, but neither worker reached 60, so none was rejected. A shared store such as Redis (RATELIMIT_STORAGE_URI=redis://…, with the redis package added to requirements.txt and a Redis service added to Compose) gives all workers one atomic counter per endpoint and client, without changing any decorator:
Bounded database work
Every PostgreSQL connection of the web application carries limits, so a slow query or a held lock fails quickly instead of occupying a worker until Gunicorn's 30-second worker timeout:
| Setting | Default | Allowed range | Effect |
|---|---|---|---|
WEB_DB_CONNECT_TIMEOUT_SECONDS |
5 | 1–60 | Stops waiting for a database connection |
WEB_DB_LOCK_TIMEOUT_MS |
3000 | 100–120000 | Fails a query that waits for a lock, for example during the snapshot switch |
WEB_DB_STATEMENT_TIMEOUT_MS |
25000 | 1000–300000 | Cancels a query that runs too long |
Values outside the range are clamped to it; values that are not integers fall back to the default. Connections are checked before reuse (pool_pre_ping). The settings are read in backend/app.py.
HTTPS and browser headers
HTTPS redirection is optional. With FORCE_HTTPS=true, a before_request hook in backend/app.py redirects plain HTTP requests to https:// with status 301. A request counts as plain HTTP when X-Forwarded-Proto is http (or absent) and the connection itself is not secure. The reverse proxy in front of the application must overwrite any X-Forwarded-Proto header sent by clients. When FORCE_HTTPS is unset or false, the application never redirects.
The application sends no Content Security Policy or other hardening headers of its own, because it serves public data without accounts or sessions. Add them at the reverse proxy if a deployment requires them.
Code
| File | Role |
|---|---|
backend/extensions.py |
The Flask-Limiter instance: client key, default limit and RATELIMIT_STORAGE_URI |
backend/app.py |
The database connection limits, pool_pre_ping and the FORCE_HTTPS redirect |
backend/blueprints/data.py, backend/blueprints/search.py, backend/blueprints/problems.py |
The limits of the map, search and Problems endpoints |
backend/blueprints/stats.py, backend/blueprints/system.py |
The limits of the statistics and pipeline status endpoints |
backend/blueprints/reports.py |
The limits of the report and export endpoints |
Related pages
- A3 Architecture for the services and their settings
- A2.5 Reports and PDFs for the export limits in context