Skip to content

fix(actors pull): block path traversal via API-supplied source file names (#1191) - #1392

Open
kuntal1461 wants to merge 1 commit into
apify:masterfrom
kuntal1461:fix/actors-pull-path-traversal
Open

fix(actors pull): block path traversal via API-supplied source file names (#1191)#1392
kuntal1461 wants to merge 1 commit into
apify:masterfrom
kuntal1461:fix/actors-pull-path-traversal

Conversation

@kuntal1461

Copy link
Copy Markdown
Contributor

Summary

  • SOURCE_FILES entries from the Apify API were used directly in mkdirSync / writeFileSync with no containment check, allowing a malicious Actor to write files outside the target pull directory via names like ../../outside.txt or /absolute/path.
  • Fix: validate every file.name with path.relative + path.isAbsolute before any filesystem operation. The isAbsolute guard also closes the Windows different-drive bypass (C:\root vs D:\outside\x.txt) where path.relative returns an absolute path that a ../ prefix check alone misses.
  • No business logic changed; all other source types (TARBALL, GITHUB_GIST, GIT_REPO) are untouched.

Changes

File Change
src/commands/actors/pull.ts Added 9-line containment check (resolve + relative + isAbsolute) before mkdirSync/writeFileSync in the SOURCE_FILES branch
test/local/commands/pull-path-traversal.test.ts New regression test file — 11 tests covering blocked traversal paths, POSIX absolute paths, Windows different-drive semantics, and all legitimate nested paths

Test plan

  • pnpm vitest run test/local/commands/pull-path-traversal.test.ts — 11/11 pass
  • pnpm run lint — clean
  • pnpm run format — clean
  • pnpm run build — clean
  • pnpm run test:local — pre-existing Python env failures only, unrelated to this change

Closes #1191

…ames

SOURCE_FILES entries from the Apify API were used directly in mkdirSync
and writeFileSync without any containment check. A malicious Actor could
supply names such as ../../outside.txt or an absolute path and write files
outside the target Actor directory.

Fix: before each filesystem operation, resolve the entry against the pull
root and verify the result stays inside it using path.relative +
path.isAbsolute. The isAbsolute guard also closes the Windows different-drive
bypass (C:\root vs D:\outside\x.txt) where path.relative returns an absolute
path that the "../" check alone would miss.

Adds regression tests covering ../traversal, deep traversal,
POSIX absolute paths, Windows different-drive semantics, and all
legitimate nested paths.

Closes apify#1191
@kuntal1461
kuntal1461 force-pushed the fix/actors-pull-path-traversal branch from 58b7841 to df39a45 Compare September 4, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ultra-review] Path traversal in apify actors pull via API-supplied filenames

2 participants