Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/content/docs/zh-cn/reference/configuration-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,42 @@ export default defineConfig({

如果 "origin" 头与请求的 `pathname` 不匹配,Astro 将返回 403 状态码,并不会渲染该页面。

#### security.allowedDomains

<p>

**类型:** `Array<RemotePattern>`<br />
**默认值:** `[]`<br />
<Since v="5.14.2" />
</p>

定义了一个在使用 SSR 时允许的主机模式列表。配置后,Astro 会将 `X-Forwarded-Host` header 与这些模式进行验证以确保安全。如果 header 不符合任何允许的模式,则该 header 会被忽略,改用请求的原始主机。

这样可以防止主机 header 注入攻击,恶意行为者可能通过发送精心构造的 `X-Forwarded-Host` header 来操纵 `Astro.url` 的值。

每个模式可以指定 `protocol`、`hostname` 和 `port`。如果提供了这三项中的任意项,都会进行验证。模式支持通配符以实现灵活的主机名匹配:

```js
{
security: {
// 示例:允许通过 HTTPS 访问 example.com 的任意子域
allowedDomains: [
{
hostname: '**.example.com',
protocol: 'https'
},
{
hostname: 'staging.myapp.com',
protocol: 'https',
port: '443'
}
]
}
}
```

如果未配置,`X-Forwarded-Host` header 不会被信任并将被忽略。

### vite

<p>
Expand Down