-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(vscode): add filesystem validation protocol for file links #11218
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
markijbema
merged 5 commits into
Kilo-Org:main
from
sylwester-liljegren:feat/file-links-2-fs-validation
Jun 29, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed5fc5a
feat(vscode): add filesystem validation protocol for file links
81aad79
fix(vscode): harden file-link fallback and type validateFiles message
d497be6
fix(vscode): scope file-link validation and fallback to the session root
c2076c8
fix(vscode): resolve real path before validating file-link containment
8cebfb4
Merge branch 'main' into feat/file-links-2-fs-validation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { realpath } from "node:fs/promises" | ||
| import * as path from "node:path" | ||
| import * as vscode from "vscode" | ||
| import { contains } from "../path-utils" | ||
|
|
||
| /** | ||
| * Stat-check candidate paths and return which ones are actual files (not directories). | ||
| * | ||
| * The webview marks every inline code span as a file-link candidate; this confirms | ||
| * which of those candidates resolve to a real file so the webview can promote them | ||
| * to clickable links and leave the rest as plain code. | ||
| * | ||
| * Containment is enforced twice so auto-validated model output can't probe host | ||
| * files outside the session `root`: | ||
| * 1. a lexical check rejects absolute paths elsewhere, UNC paths, and `../` | ||
| * traversal before touching the filesystem at all; | ||
| * 2. the candidate's real path (symlinks resolved) must still be inside the | ||
| * real root, so a checked-in symlink can't escape the root either. | ||
| */ | ||
| export function validateFiles(root: string, paths: string[]): Promise<string[]> { | ||
| return Promise.resolve(realpath(root)).then( | ||
| (realRoot) => { | ||
| const check = (p: string): Promise<string | null> => { | ||
| if (!contains(root, p)) return Promise.resolve(null) | ||
| return Promise.resolve(realpath(path.resolve(root, p))).then( | ||
| (real) => { | ||
| if (!contains(realRoot, real)) return null | ||
| return Promise.resolve(vscode.workspace.fs.stat(vscode.Uri.file(real))).then( | ||
| (s) => (s.type & vscode.FileType.File ? p : null), | ||
| () => null, | ||
| ) | ||
| }, | ||
| () => null, | ||
| ) | ||
| } | ||
| return Promise.all(paths.map(check)).then((r) => r.filter((x): x is string => x !== null)) | ||
| }, | ||
| () => [], | ||
| ) | ||
| } |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING:
contains()only enforces lexical containment, so symlink escapes can still probe files outside the session root.path.resolve()/path.relative()treatroot/link/passwdas in-tree even whenlinkis a symlink to/etc, sovalidateFiles()will still callworkspace.fs.stat()on an external target through any checked-in symlink. Once the stacked UI auto-validates code spans, model output can still confirm arbitrary host files this way. Consider resolving the real path before the containment check, or rejecting symlinked path segments entirely.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.