Skip to content

feat: validate copy src paths are relative and within context directory#1106

Merged
mishushakov merged 20 commits intomainfrom
mishushakov/relative-path-validation
Feb 5, 2026
Merged

feat: validate copy src paths are relative and within context directory#1106
mishushakov merged 20 commits intomainfrom
mishushakov/relative-path-validation

Conversation

@mishushakov
Copy link
Member

@mishushakov mishushakov commented Jan 29, 2026

Add path validation to the copy method in both JS and Python SDKs to ensure source paths are always relative and don't escape the context directory.

This prevents:

  • Absolute paths like /absolute/whatever (Unix) or C:\whatever (Windows)
  • Path traversal attacks like ../whatever or ./foo/../../../bar

The validation works cross-platform using Node's path.isAbsolute/normalize and Python's os.path.isabs/normpath plus PureWindowsPath for detecting Windows paths on Unix.


Note

Medium Risk
Changes behavior of copy/copy_items to throw earlier for previously-accepted absolute or escaping paths, which could break some consumers; logic is localized and well-covered by tests.

Overview
Prevents path traversal in template copy operations by validating src is relative and does not escape the context directory (rejects absolute paths and ..-based escapes) in both the JS and Python SDKs.

Updates copyItems/copy_items error handling to preserve the caller’s stack trace when validation fails, adds unit coverage for the new path validator plus new stack-trace tests for absolute-path failures, and ships as patch releases via a changeset.

Written by Cursor Bugbot for commit c1a8eb9. This will update automatically on new commits. Configure here.

Add path validation to the copy method in both JS and Python SDKs to ensure
source paths are always relative and don't escape the context directory.

This prevents:
- Absolute paths like /absolute/whatever (Unix) or C:\whatever (Windows)
- Path traversal attacks like ../whatever or ./foo/../../../bar

The validation works cross-platform using Node's path.isAbsolute/normalize
and Python's os.path.isabs/normpath plus PureWindowsPath for detecting
Windows paths on Unix.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2026

🦋 Changeset detected

Latest commit: c1a8eb9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@e2b/python-sdk Patch
e2b Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

mishushakov and others added 8 commits January 29, 2026 15:54
Keep only the unit tests for validateRelativePath.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mishushakov mishushakov marked this pull request as ready for review January 29, 2026 15:35
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c49e71beb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Use path.win32.isAbsolute() in addition to path.isAbsolute() to ensure
Windows-style absolute paths (C:\foo, \\server\share) are rejected on
all platforms, not just Windows.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The escape check now correctly distinguishes between:
- Path escapes like '../foo' (rejected)
- Valid filenames like '..myconfig' (allowed)

Changed from `startsWith('..')` to checking for '..' followed by a path
separator. Also added cross-platform Windows path escape detection using
path.win32/ntpath to catch '..\' escapes on Unix.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
mishushakov and others added 3 commits January 29, 2026 17:23
Remove copyAbsolute/copy_absolute entries from failure maps since the
corresponding tests don't invoke the build process that uses them.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When copyItems calls copy internally, the stack trace captured in copy
points to SDK internals rather than the user's copyItems call site.

Now copyItems validates all paths with its own stack trace before
delegating to copy, so validation errors point to user code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jakubno jakubno self-assigned this Feb 2, 2026
cursor[bot]

This comment was marked as outdated.

@mishushakov mishushakov force-pushed the mishushakov/relative-path-validation branch from 4543e97 to 90bb89b Compare February 3, 2026 16:20
Copy link
Member

@jakubno jakubno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks much better! Can we simplify it even little bit more by not doing windows path resolution on unix and vice versa?

can you add tests for the issue we had before ./a/./../../b?

mishushakov and others added 3 commits February 4, 2026 16:13
Rely on Node's path.isAbsolute/normalize and Python's os.path.isabs/normpath
instead of explicitly checking Windows paths on all platforms. Windows path
tests now only run on Windows.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move the repeated TracebackType construction pattern into a reusable
make_traceback() function in template/utils.py, simplifying 7 call sites
in main.py.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mishushakov mishushakov merged commit 5e9c6d6 into main Feb 5, 2026
16 of 20 checks passed
@mishushakov mishushakov deleted the mishushakov/relative-path-validation branch February 5, 2026 12:54
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.

2 participants