fix(codeql): go/path-injection in pkg/server/session_manager.go:542#3758
Merged
Conversation
User-supplied WorkingDir (POST /api/sessions body) was passed through filepath.Abs and then directly to os.Stat without any containment check, allowing an authenticated caller to probe or operate on arbitrary filesystem locations (go/path-injection, CodeQL alert #57). Add resolveWithinRoot which canonicalises the requested path via filepath.EvalSymlinks (on both the candidate and the allowed root) and then rejects any path whose filepath.Rel result escapes the root with a ".." prefix. The allowed root defaults to the server's configured WorkingDir (runConfig.WorkingDir), falling back to the process working directory when none is configured. Symlink escapes (a link inside root pointing outside), dot-dot traversal, and sibling-directory attacks are all covered by the new test suite.
forbidigo rule disallows context.Background() in tests.
ronan-thibaut-glitch
marked this pull request as ready for review
July 20, 2026 16:03
Sayt-0
approved these changes
Jul 20, 2026
This was referenced Jul 21, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
WorkingDirfield supplied in the POST /api/sessions request body was resolved withfilepath.Absand passed directly toos.Statwithout checking whether it lies within any permitted scope. An authenticated caller could setWorkingDirto/etc,/root, or any other directory and cause the AI agent to operate on arbitrary filesystem locations — a horizontal privilege escalation risk in multi-user deployments (CodeQL rulego/path-injection, alert #57, line 542).The fix adds two helpers to
SessionManager:workingDirRoot(returns the server's configuredWorkingDirfromrunConfig, falling back to the process working directory) andresolveWithinRoot(callsfilepath.EvalSymlinkson both the candidate path and the root to defeat symlink escapes, then usesfilepath.Relto verify the result does not escape the root via../components or an absolute path on a different drive). The taintedabsWdnow passes throughresolveWithinRootbefore reachingos.Stat, breaking the alerted data flow. Symlink-escape, sibling-directory, and dot-dot traversal attacks are each covered by the newpkg/server/session_workingdir_test.gotest file.