fix: 限制文件 API 访问会话工作区
This commit is contained in:
6 files changed
+307
-44
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { afterAll, describe, expect, it } from 'vitest'
|
||||
import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs'
|
||||
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, symlinkSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { writeWorkspaceUpload } from '../src/fs-operations.ts'
|
||||
@@ -103,6 +103,23 @@ describe('writeWorkspaceUpload', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('refuses upload directories and targets that resolve outside the workspace', async () => {
|
||||
const outside = mkdtempSync(join(tmpdir(), 'dsh-sidebar-upload-symlink-outside-'))
|
||||
const link = join(root, 'upload-link')
|
||||
try {
|
||||
symlinkSync(outside, link)
|
||||
await expect(writeWorkspaceUpload({
|
||||
cwd: root, dir: link, relativePath: 'x.txt', chunks: chunksOf('x'), limit: 1024,
|
||||
})).rejects.toMatchObject({ code: 'forbidden' })
|
||||
await expect(writeWorkspaceUpload({
|
||||
cwd: root, dir: root, relativePath: 'upload-link/x.txt', chunks: chunksOf('x'), limit: 1024,
|
||||
})).rejects.toMatchObject({ code: 'forbidden' })
|
||||
} finally {
|
||||
rmSync(link, { force: true })
|
||||
rmSync(outside, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('refuses oversized uploads without leaving a target or temp file', async () => {
|
||||
const target = join(root, 'big.bin')
|
||||
await expect(writeWorkspaceUpload({
|
||||
|
||||
Reference in new issue
Block a user