fix(trust-fence): Origin 校验改按 hostname 比较,对齐 DSH 网关栅栏(Edge 151 无端口 Origin 修复)
镜像栅栏此前按 host(含端口)比较 Origin,而部分 Chromium 构建(Edge 151)会把非默认端口 loopback 页面的 Origin 序列化为不带端口的形式,导致 /sidebar/* 在 Edge 151 下全部 403 forbidden。DSH 官方栅栏(api-request-trust.ts)已改为 hostname 比较,本提交同步该语义:端口不再重决信任,Host 栅栏与 sec-fetch-site 拒绝逻辑不变。 测试:tests/trusted-hosts.spec.ts 新增无端口 Origin 放行、不同 hostname 拒绝、null origin 拒绝三个回归用例;本地 scratch 挂载 + curl 实测通过。
This commit is contained in:
1 parent
bcd60234ac
commit
8181e13b52
3 files changed
+107
-1
No files matched your search
@@ -147,6 +147,55 @@ describe('remote-access trust (webRuntime.trustedHosts)', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('accepts an Origin that names the Host hostname without its port (Edge 151 serialization)', async () => {
|
||||
// Some Chromium builds serialize the Origin of a non-default-port loopback
|
||||
// page without the port; refusing those bricks every /sidebar route.
|
||||
const { api, cleanup } = mount([])
|
||||
try {
|
||||
const res = fakeRes()
|
||||
await api(req('POST', '/sidebar/api/session.cwd', {
|
||||
host: '127.0.0.1:3080',
|
||||
'sec-fetch-site': 'same-origin',
|
||||
origin: 'http://127.0.0.1',
|
||||
}, '{"sessionId":"test-session"}'), res as unknown as ServerResponse)
|
||||
expect(res.status).toBe(200)
|
||||
} finally {
|
||||
cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects an Origin whose hostname differs from the Host even on loopback', async () => {
|
||||
// hostname, not port, re-decides trust: a same-127/8 address that is not
|
||||
// the page's own hostname is still a different authority.
|
||||
const { api, cleanup } = mount([])
|
||||
try {
|
||||
const res = fakeRes()
|
||||
await api(req('POST', '/sidebar/api/session.cwd', {
|
||||
host: '127.0.0.1:3080',
|
||||
'sec-fetch-site': 'same-origin',
|
||||
origin: 'http://127.0.0.2',
|
||||
}, '{"sessionId":"test-session"}'), res as unknown as ServerResponse)
|
||||
expect(res.status).toBe(403)
|
||||
} finally {
|
||||
cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects the opaque "null" origin', async () => {
|
||||
const { api, cleanup } = mount([])
|
||||
try {
|
||||
const res = fakeRes()
|
||||
await api(req('POST', '/sidebar/api/session.cwd', {
|
||||
host: '127.0.0.1:3080',
|
||||
'sec-fetch-site': 'same-origin',
|
||||
origin: 'null',
|
||||
}, '{"sessionId":"test-session"}'), res as unknown as ServerResponse)
|
||||
expect(res.status).toBe(403)
|
||||
} finally {
|
||||
cleanup()
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects cross-site browser markers even for a trusted host', async () => {
|
||||
const { api, cleanup } = mount(['example.com'])
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user