You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/en/reference/configuration-reference.mdx
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -409,6 +409,44 @@ one of the following `content-type` headers: `'application/x-www-form-urlencoded
409
409
410
410
If the "origin" header doesn't match the `pathname` of the request, Astro will return a 403 status code and will not render the page.
411
411
412
+
#### security.allowedDomains
413
+
414
+
<p>
415
+
416
+
**Type:**`Array<RemotePattern>`<br />
417
+
**Default:**`[]`<br />
418
+
<Sincev="5.14.2" />
419
+
</p>
420
+
421
+
Defines a list of permitted host patterns for incoming requests when using SSR. When configured, Astro will validate the `X-Forwarded-Host` header
422
+
against these patterns for security. If the header doesn't match any allowed pattern, the header is ignored and the request's original host is used instead.
423
+
424
+
This prevents host header injection attacks where malicious actors can manipulate the `Astro.url` value by sending crafted `X-Forwarded-Host` headers.
425
+
426
+
Each pattern can specify `protocol`, `hostname`, and `port`. All three are validated if provided.
427
+
The patterns support wildcards for flexible hostname matching:
428
+
429
+
```js
430
+
{
431
+
security: {
432
+
// Example: Allow any subdomain of example.com on https
433
+
allowedDomains: [
434
+
{
435
+
hostname:'**.example.com',
436
+
protocol:'https'
437
+
},
438
+
{
439
+
hostname:'staging.myapp.com',
440
+
protocol:'https',
441
+
port:'443'
442
+
}
443
+
]
444
+
}
445
+
}
446
+
```
447
+
448
+
When not configured, `X-Forwarded-Host` headers are not trusted and will be ignored.
0 commit comments