-
Notifications
You must be signed in to change notification settings - Fork 0
Sync the api docs with the new rate limiting backend feature #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8a3d365
3ad2415
905b37f
e55d284
8b7bd76
817d86f
5f46538
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ Here is the typical execution order for a request to a protected data endpoint l | |
|
|
||
| 3. **Data Route Middleware (`/routes/api/v1/data/_middleware.dart`)** | ||
| - **Require Authentication:** Checks if a `User` object exists in the context. If not, it immediately aborts the request with a `401 Unauthorized` error. | ||
| - **Rate Limiting:** If the user is not an admin, it applies a rate limit based on the user's ID. If the limit is exceeded, it aborts with a `429 Too Many Requests` error. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an inconsistency in the documentation regarding which roles bypass rate limiting. This file states that only Assuming |
||
| - **Model Validation:** Validates the `?model=` query parameter and injects the corresponding `ModelConfig` into the context. | ||
| - **Authorization:** Checks if the authenticated user has the required permissions to perform the requested action on the specified model. If not, it aborts with a `403 Forbidden` error. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| title: 'Feature: Rate Limiting' | ||
| description: An overview of the API server's built-in rate limiting to prevent abuse and ensure stability. | ||
| --- | ||
|
|
||
| import { Aside } from '@astrojs/starlight/components'; | ||
|
|
||
| To ensure the stability and security of the API, the server includes a built-in rate-limiting feature. This system automatically tracks the number of requests from a given source and blocks further requests if they exceed a configured limit within a specific time window. | ||
|
|
||
| This is crucial for preventing abuse, such as brute-force attacks on the authentication endpoints or overly aggressive polling of the data API. | ||
|
|
||
| ### How It Works | ||
|
|
||
| The rate-limiting mechanism is implemented as a middleware that runs on specific routes. It uses the client's IP address as the primary identifier for tracking requests. | ||
fulleni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| There are two distinct rate-limiting configurations applied to different parts of the API: | ||
|
|
||
| 1. **Sensitive Endpoint Limiting:** | ||
| - **Target:** The `/api/v1/auth/request-code` endpoint. | ||
| - **Purpose:** This endpoint is more sensitive as it triggers an email to be sent. The rate limit here is intentionally strict to prevent spamming users with verification codes. | ||
| - **Default Limit:** 3 requests per 24 hours. | ||
|
|
||
| 2. **General Data API Limiting:** | ||
| - **Target:** All endpoints under `/api/v1/data`. | ||
| - **Purpose:** This provides a generous limit for general application usage while still protecting the server from excessively frequent requests from a single client. | ||
| - **Default Limit:** 1000 requests per 60 minutes. | ||
|
|
||
| <Aside type="note" title="Bypassing Limits"> | ||
| Users with the `admin` or `publisher` role automatically bypass all rate limits, ensuring that administrative tasks are never blocked. | ||
| </Aside> | ||
|
|
||
| ### Configuration | ||
|
|
||
| These limits are configurable via environment variables, allowing you to adjust them for your specific production needs. For details, see the [Configure Environment Variables](/docs/api-server/guides/configure-environment-variables) guide. | ||
|
|
||
| ### Error Response | ||
|
|
||
| When a client exceeds a rate limit, the API will respond with an HTTP `429 Too Many Requests` status code and the following error payload: | ||
|
|
||
| ```json | ||
| { | ||
| "error": { | ||
| "code": "forbidden", | ||
fulleni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "message": "You have made too many requests. Please try again later." | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.