Skip to content

fix(repository): prevent path traversal in exportEnvironmentFile - #365

Merged
grouville merged 2 commits into
dagger:mainfrom
awdemos:fix/337-path-traversal
Aug 12, 2026
Merged

fix(repository): prevent path traversal in exportEnvironmentFile#365
grouville merged 2 commits into
dagger:mainfrom
awdemos:fix/337-path-traversal

Conversation

@awdemos

@awdemos awdemos commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Closes #337

Strengthens exportEnvironmentFile so the resolved file path cannot escape the worktree root. Adds a filepath.Rel check after filepath.Join(worktreePath, clean) and rejects any path that resolves outside the worktree.

The existing guard rejected filepath.IsAbs and raw .. prefixes; this change also catches cases where a cleaned relative path still resolves above the worktree.

Verification:

  • go build ./...
  • go test -short ./repository/... ./environment/... ./mcpserver/... ./cmd/container-use/agent/...

This branch is based on the current dagger/container-use:main (0d87ad6) and merges cleanly as a fast-forward.

Strengthens exportEnvironmentFile so the resolved file path cannot escape
the worktree root. Adds a filepath.Rel check after filepath.Join and
rejects any path that resolves outside the worktree.

Based on the bug report in dagger#337
…t test

The previous test only asserted that test inputs looked like escaping
paths. This change extracts the validation logic into a testable helper
and adds focused tests that actually exercise the function.
@awdemos awdemos self-assigned this Aug 12, 2026
@grouville
grouville self-requested a review August 12, 2026 16:26
@grouville
grouville merged commit 2e43e62 into dagger:main Aug 12, 2026
4 checks passed
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.

[Bug]: Path traversal in exportEnvironmentFile allows writing files outside the worktree

3 participants