Skip to content

Sanitize dataset ZIP entry names - #4

Draft
vavo wants to merge 1 commit into
mainfrom
vavofix-untrusted-zip-paths-in-exports
Draft

Sanitize dataset ZIP entry names#4
vavo wants to merge 1 commit into
mainfrom
vavofix-untrusted-zip-paths-in-exports

Conversation

@vavo

@vavo vavo commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Imported ZIP entries were preserved verbatim and later written into exported archives, which allowed attacker-controlled paths (e.g. ..\\..\\outside.jpg, absolute paths, drive-letter paths, or entries with slashes) to survive and create unsafe ZIP entry names on export.
  • The change prevents downstream extractors or training workflows from writing files outside the intended extraction directory by ensuring exported names are safe, basenames only, and normalized.

Description

  • Added filename helper functions: isSafeDatasetFileName(filename) to validate that a name is a plain basename without path separators, traversal (..), drive letters, or absolute path prefixes; normalizeDatasetImageName(filename) to normalize .jpeg to .jpg and return null for unsafe names; and getDatasetTextFileName(imageName) to generate paired .txt names from validated image names.
  • Updated ZIP import (handleZipUpload) to skip ZIP entries that fail isSafeDatasetFileName and to use normalizeDatasetImageName when constructing browser File objects so imported files have safe, normalized names.
  • Updated ZIP export (handleExport) to derive export entry names via normalizeDatasetImageName and getDatasetTextFileName, skipping any items that do not produce safe names instead of writing item.file.name directly into the output ZIP.
  • Added regression tests in tests/prompt-settings.test.mjs that exercise the safety helpers, .jpeg.jpg normalization, paired .txt name generation, and several unsafe path variants to prevent regressions.

Testing

  • Ran the test suite with node --test tests/prompt-settings.test.mjs, which executed the new regression and the existing tests; all tests passed (29 passing, 0 failing).
  • Modified files: tagpilot.html and tests/prompt-settings.test.mjs, and validated the new import/export behavior through the unit tests described above.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant