fix: use streaming and add path validation

- Replace fs.readFileSync() with fs.createReadStream() to prevent memory exhaustion
- Export validatePath() from fs-utils.ts
- Use validatePath() to validate full path including project and version parameters
- Fix incomplete path traversal protection
- Add filename encoding in Content-Disposition header

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 02:01:38 +08:00
parent 7d5ee36f56
commit cf7d3d5618
2 changed files with 11 additions and 17 deletions

View File

@@ -6,7 +6,7 @@ import { RESOURCE_PATH } from './constants';
/**
* Validate that a path doesn't escape the base directory (prevents path traversal)
*/
function validatePath(basePath: string, ...segments: string[]): string {
export function validatePath(basePath: string, ...segments: string[]): string {
const fullPath = path.resolve(basePath, ...segments);
const normalizedBase = path.resolve(basePath);
if (!fullPath.startsWith(normalizedBase)) {