Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(files): don't reject external URLs containing '..' in file parse validation#4821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
waleedlatif1
merged 4 commits into
staging
from
waleedlatif1/file-block-path-traversal-errorMay 31, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e0d676b
fix(files): don't reject external URLs containing '..' in file parse …
waleedlatif1 e34ad51
test(files): fix external-URL assertion to handle undefined error
waleedlatif1 a9a5503
test(files): assert success explicitly in external-URL traversal test
waleedlatif1 499e834
fix(files): keep traversal protection for https URLs matching interna…
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -419,13 +419,33 @@ function assertParsedContentWithinLimit(content: string, maxBytes?: number): str | ||
| } | ||
| /** | ||
| * Validate file path for security - prevents null byte injection and path traversal attacks | ||
| * Validate file path for security - prevents null byte injection and path traversal attacks. | ||
| * | ||
| * External URLs (`http`/`https`) are fetched over HTTP — with SSRF protection applied | ||
| * downstream in `fetchExternalUrlToWorkspace` (DNS resolution + private/reserved IP blocking) | ||
| * — and are never resolved against the filesystem, so `..`/`~` are legal URL content and must | ||
| * not be rejected. Providers such as Slack routinely emit slugs containing a literal `...`. | ||
| * | ||
| * Internal file URLs (`/api/files/serve/...`) ARE resolved to storage keys and filesystem | ||
| * paths via `extractStorageKey`, so they keep full traversal protection. The external | ||
| * short-circuit explicitly excludes them: `parseFileSingle` routes anything matching | ||
| * `isInternalFileUrl` to `handleCloudFile` (even an absolute `https://host/api/files/serve/...`), | ||
| * so such inputs must stay subject to the `..`/`~` checks rather than being waved through as | ||
| * external URLs. Only the leading-`/` "outside allowed directory" check is relaxed for them, | ||
| * since that prefix is expected. | ||
| */ | ||
| function validateFilePath(filePath: string): { isValid: boolean; error?: string } { | ||
| if (filePath.includes('\0')) { | ||
| return { isValid: false, error: 'Invalid path: null byte detected' } | ||
| } | ||
| if ( | ||
| (filePath.startsWith('http://') || filePath.startsWith('https://')) && | ||
| !isInternalFileUrl(filePath) | ||
| ) { | ||
| return { isValid: true } | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (filePath.includes('..')) { | ||
| return { isValid: false, error: 'Access denied: path traversal detected' } | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.