feat: add secure remote channel media

This commit is contained in:
lofyer
2026-08-09 20:33:35 +08:00
parent 6c891f3522
commit 66b098ae36
46 changed files with 4403 additions and 1594 deletions
@@ -13,6 +13,7 @@ const originalParentPort = Object.getOwnPropertyDescriptor(
process,
'parentPort'
)
const originalFetch = global.fetch
afterEach(() => {
if (originalParentPort) {
@@ -20,6 +21,7 @@ afterEach(() => {
} else {
delete (process as Partial<NodeJS.Process>).parentPort
}
global.fetch = originalFetch
vi.resetModules()
})
@@ -38,4 +40,36 @@ describe('Weixin utility-process entry', () => {
{ type: 'status', status: 'stopped' }
])
})
it('does not follow API redirects outside Tencent Weixin hosts', async () => {
const parentPort = new FakeParentPort()
Object.defineProperty(process, 'parentPort', {
configurable: true,
value: parentPort
})
global.fetch = vi.fn(async () =>
new Response(null, {
status: 307,
headers: {
location: 'https://attacker.example/collect'
}
})
) as typeof fetch
await import('./wechat-sidecar')
parentPort.emit('message', {
data: { type: 'start_login' }
})
await vi.waitFor(() =>
expect(parentPort.messages).toContainEqual(
expect.objectContaining({
type: 'status',
status: 'failed',
detail: expect.stringContaining('不受信任')
})
)
)
expect(fetch).toHaveBeenCalledOnce()
})
})