Skip to content

Commit 89f5cdf

Browse files
intility-claude[bot]intility-claude[bot]
andauthored
docs: auto-generated docs for #116 (#117)
## Auto-generated Documentation This PR was generated automatically by the Claude Auto Docs workflow. **Source repository:** `intility/Intility.JsonApiToolkit` **Source PR:** #116 > **Note** > Review all generated content carefully before merging. Co-authored-by: intility-claude[bot] <2458755+intility-claude[bot]@users.noreply.github.com>
1 parent 0f7af6b commit 89f5cdf

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

docs/docs/getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ dotnet add package Intility.JsonApiToolkit
5050
options.MaxFilterDepth = 5; // Default: 3
5151
options.MaxPageSize = 200; // Default: 100
5252
options.DefaultPageSize = 25; // Default: 10
53+
options.StrictPagination = true; // Default: false
5354
options.EnableDatabaseProjection = true; // Default: false
5455
});
5556
```

docs/docs/querying.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ JsonApiToolkit provides robust support for JSON:API querying, including filterin
3232
The `sort` parameter allows multiple sort criteria. Prefixing a field with a minus (`-`) indicates descending order.
3333
- Example: `GET /api/books?sort=title,-publishedDate`
3434

35-
- **Pagination (`page[number]` and `page[size]`):**
35+
- **Pagination (`page[number]` and `page[size]`):**
3636
Control how many results are returned and which page to view.
3737
- Example: `GET /api/books?page[number]=2&page[size]=5`
38+
- By default, invalid pagination values (page number less than 1, page size exceeding `MaxPageSize`) are silently clamped to valid ranges. Enable `StrictPagination` to return 400 errors instead (see [Security](security.md#strict-pagination)).
3839

3940
- **Inclusion (`include`):**
4041
Specify which related resources should be included in the response.
@@ -121,7 +122,7 @@ JsonApiToolkit enforces the following query limits to ensure predictable perform
121122
| Max Filter Depth | 3 | Maximum nesting of filter groups |
122123
| Max Filter Value Length | 1000 | Maximum characters per filter value |
123124
| Max Include Depth | 3 | Maximum include path depth (e.g., `author.posts.comments`) |
124-
| Max Page Size | 100 | Maximum items per page (silently clamped) |
125+
| Max Page Size | 100 | Maximum items per page (clamped or rejected based on `StrictPagination`) |
125126
126127
These limits are configurable via `JsonApiOptions`. See the [Security](security.md#query-complexity-limits) documentation for configuration details.
127128

docs/docs/security.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ builder.Services.AddJsonApiToolkit(options => {
9696
options.MaxIncludeDepth = 3; // Max include path depth (default: 3)
9797
options.MaxPageSize = 100; // Max page size, clamped (default: 100)
9898
options.DefaultPageSize = 10; // Default when not specified (default: 10)
99+
options.StrictPagination = false; // Reject invalid pagination (default: false)
99100
});
100101
```
101102

@@ -108,7 +109,7 @@ builder.Services.AddJsonApiToolkit(options => {
108109
| `MaxFilterDepth` | Returns 400 Bad Request |
109110
| `MaxFilterValueLength` | Returns 400 Bad Request |
110111
| `MaxIncludeDepth` | Returns 400 Bad Request |
111-
| `MaxPageSize` | Silently clamped to max value |
112+
| `MaxPageSize` | Clamped (default) or 400 Bad Request (`StrictPagination`) |
112113

113114
### Error Response
114115

@@ -168,6 +169,50 @@ When filtering on a non-allowed relationship:
168169
> [!NOTE]
169170
> This validation only applies when `[AllowedIncludes]` is present. Without the attribute, all filter paths are allowed.
170171
172+
## Strict Pagination
173+
174+
By default, JsonApiToolkit silently clamps invalid pagination parameters to valid ranges for backwards compatibility. Enable `StrictPagination` to return 400 Bad Request errors instead.
175+
176+
### Configuration
177+
178+
```csharp
179+
builder.Services.AddJsonApiToolkit(options => {
180+
options.StrictPagination = true;
181+
});
182+
```
183+
184+
### Behavior
185+
186+
When `StrictPagination` is enabled, the following values are rejected with 400 Bad Request:
187+
188+
- `page[number]` less than 1 (e.g., `page[number]=0` or `page[number]=-5`)
189+
- `page[size]` less than 1 (e.g., `page[size]=0` or `page[size]=-10`)
190+
- `page[size]` exceeding `MaxPageSize` (e.g., `page[size]=200` when `MaxPageSize=100`)
191+
192+
When disabled (default), these values are silently clamped:
193+
194+
- `page[number]` less than 1 becomes 1
195+
- `page[size]` exceeding `MaxPageSize` becomes `MaxPageSize`
196+
197+
### Error Response
198+
199+
```json
200+
{
201+
"errors": [{
202+
"status": "400",
203+
"code": "INVALID_PAGE_SIZE",
204+
"title": "Invalid page size",
205+
"detail": "Page size '200' exceeds maximum allowed size of 100. Reduce page size or configure a higher limit via JsonApiOptions.MaxPageSize.",
206+
"source": { "parameter": "page[size]" },
207+
"meta": {
208+
"value": 200,
209+
"max": 100,
210+
"configKey": "JsonApiOptions.MaxPageSize"
211+
}
212+
}]
213+
}
214+
```
215+
171216
## DoS Protection
172217

173218
The query complexity limits protect against several denial-of-service attack vectors:

0 commit comments

Comments
 (0)