Security Configuration
The framework collects all security-related parameters — upload size, remote redirect count, login lockout, CSRF, host allow-list, external call timeout — under the Security configuration section, so that they no longer live as magic numbers scattered across the code base.
Every option is optional: when it is not configured, the defaults below apply and the behaviour is exactly the same as before the configuration options existed.
{
"Security": {
"MaxUploadSize": 10485760,
"MaxRemoteRedirects": 3,
"LoginFailureLimit": 5,
"LoginLockout": "00:10:00",
"AllowedHosts": [],
"AntiforgeryEnabled": true,
"AntiforgeryHeaderName": "X-CSRF-TOKEN",
"RateLimitEnabled": true,
"RateLimitPermitLimit": 60,
"RateLimitWindow": "00:01:00",
"ExternalApiTimeout": "00:00:10"
}
}
Options
| Option | Type | Default | Where it applies |
|---|---|---|---|
MaxUploadSize |
long | 10485760 (10MB) |
Maximum size of a single uploaded file. The HTTP layer (FormOptions.MultipartBodyLengthLimit, enforced before multipart parsing) and the business layer (FileService) read the same value, so the two layers can never disagree |
MaxRemoteRedirects |
int | 3 |
Maximum number of redirects allowed when downloading a remote image (saving a remote image in the editor, scheduled cover downloads) |
LoginFailureLimit |
int | 5 |
Number of consecutive failed logins before the account is locked. Non-positive values are treated as a misconfiguration and fall back to the default |
LoginLockout |
TimeSpan | 00:10:00 |
How long the account stays locked. Non-positive values fall back to the default |
AllowedHosts |
string[] | [] |
Allow-list of request hosts. Exact matches (example.com), matches with a port (example.com:8080) and wildcard subdomains (*.example.com) are supported; an empty list means no restriction, * allows everything. Requests outside the list get a 400 response |
AntiforgeryEnabled |
bool | true |
Whether the CSRF check is enabled. When disabled, the write endpoints marked by the framework no longer validate the Antiforgery token (not recommended) |
AntiforgeryHeaderName |
string | X-CSRF-TOKEN |
Request header that carries the Antiforgery token in cookie-less scenarios (e.g. JS uploads from the rich-text editor) |
RateLimitEnabled |
bool | true |
Whether anonymous endpoint rate limiting is enabled. Currently consumed by the WeChat extension's anonymous endpoints (login exchange, data decryption, QR code) |
RateLimitPermitLimit |
int | 60 |
A global tightening ceiling for the rate limit: the smaller of this value and each endpoint's own threshold is used, so it can only make limiting stricter, never loosen an endpoint's safety ceiling. Non-positive values are treated as "not configured" |
RateLimitWindow |
TimeSpan | 00:01:00 |
Length of the rate limit window. Non-positive values fall back to one minute |
ExternalApiTimeout |
TimeSpan | 00:00:10 |
Timeout for calls to external services (WeChat and other third-party APIs). The framework's own image download client uses a fixed 30-second timeout and is not affected by this option |
Notes
- Always configure
AllowedHostsin a multi-tenant deployment: the tenant is resolved from the request Host, and the Host header is controlled by the client. Without an allow-list an attacker can forge the Host header and switch to another tenant's database. - The upload limit has two layers, but one source: the HTTP layer rejects before parsing, the business layer checks again, and both read the same
MaxUploadSize— change it in one place. - CSRF only protects the endpoints the framework marks: your own endpoints are unmarked and always pass through; a failed validation returns 400 instead of bubbling up as a 500.
- A misconfiguration cannot lock login out for good:
LoginFailureLimitandLoginLockoutfall back to the defaults when set to zero or a negative value. - The rate limit can only be tightened, not loosened: lowering
RateLimitPermitLimittightens every WeChat anonymous endpoint at once; raising it does not lift an endpoint's own ceiling (the QR code endpoint's 10 requests/minute is the red line that protects theaccess_tokenquota). - TimeSpan format:
"00:10:00"(hours:minutes:seconds),"1.00:00:00"(days.hours:minutes:seconds).
Related Documentation
- File Management — uploads, directory groups, image processing limits
- Multi-tenancy — tenant isolation and the host allow-list
- Deployment — Nginx, HTTPS, Windows services and other production topics