(userTempDir: string, targetPath: string)
| 307 | } |
| 308 | |
| 309 | function assertWithinUserDir(userTempDir: string, targetPath: string): void { |
| 310 | const base = path.resolve(userTempDir); |
| 311 | const resolved = path.resolve(targetPath); |
| 312 | if (resolved !== base && !resolved.startsWith(base + path.sep)) { |
| 313 | throw handleApiError( |
| 314 | 400, |
| 315 | `Path traversal detected: ${resolved} escapes ${base}`, |
| 316 | "Invalid upload path.", |
| 317 | ); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | async function handleChunkUpload(formData: any[], userId: string) { |
| 322 | const fileId = formData.find((p) => p.name === "fileId")?.data.toString(); |
no test coverage detected