T09 · Insecure Skill Coding Practices
- Location
scripts/video_gen.js:142- Finding
Unrestricted Local File Read and Upload to WeryAI
- Content
View full analysis
Vulnerability Details
File Location:
scripts/video_gen.js, lines 142–263
Vulnerability Type: Arbitrary local file disclosure through an unrestricted upload path
Risk Level: MediumVulnerable Code
js function normalizeLocalFilePath(value) { if (typeof value !== 'string' || !value.trim()) return null; if (value.startsWith('file://')) { return new URL(value); } return path.resolve(value); } function inferMimeType(filePath) { return IMAGE_MIME_TYPES[path.extname(filePath).toLowerCase()] || 'application/octet-stream'; } async function uploadFileToPublicUrl(inputPath, apiKey) { const resolvedPath = normalizeLocalFilePath(inputPath); if (!resolvedPath) { throw new Error(`Invalid local image path: ${inputPath}`); } const filePath = resolvedPath instanceof URL ? fileURLToPath(resolvedPath) : path.resolve(resolvedPath); let stat; try { stat = await fs.stat(filePath); } catch { throw new Error(`Local image file not found: ${inputPath}`); } if (!stat.isFile()) { throw new Error(`Local image path is not a file: ${inputPath}`); } const fileBuffer = await fs.readFile(filePath); const fileName = path.basename(filePath); const mimeType = inferMimeType(filePath); const form = new FormData(); form.append('batch_no', makeUploadBatchNo()); form.append('fixed', 'false'); form.append('file', new Blob([fileBuffer], { type: mimeType }), fileName); const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), 60_000); let res; try { res = await fetch(MODELS_BASE_URL + UPLOAD_API_PATH, { method: 'POST', headers: { Authorization: `Bearer ${apiKey}`, }, body: form, signal: controller.signal, }); } catch (err) { clearTimeout(timer); if (err.name === 'AbortError') { throw new Error(`Upload timeo ...[truncated 4270 chars]- Remediation
View remediation
Remediation Suggestions
- Disable local-file handling by default. Require an explicit option such as
--allow-local-uploadbefore accepting any local path. - Require confirmation immediately before reading and uploading the file, displaying the canonical path, destination host, file size, and privacy implications.
- Restrict local inputs to a dedicated, user-approved directory. Resolve the canonical path with
fs.realpath()and verify it remains inside that directory. - Reject symlinks or validate their canonical target before access to prevent escaping the approved directory.
- Allowlist supported image extensions and verify file signatures or magic bytes instead of relying solely on filename extensions.
- Reject unknown formats rather than falling back to
application/octet-stream. - Enforce a conservative maximum file size before reading it. Prefer streaming uploads to buffering the complete file in memory.
- Separate public URL inputs from local paths through explicit fields, such as
image_urlandlocal_image, so malformed URLs are not silently reinterpreted as filesystem paths. - Consider removing local upload support entirely because public HTTPS image URLs are already the documented normal path and satisfy the Skill's core functionality.
- Disable local-file handling by default. Require an explicit option such as
