fix(security): Symlink TOCTOU race condition

This commit is contained in:
Goksu Ceylan 2026-02-19 08:46:39 -05:00
parent 213274002a
commit dd75f0b56e

View file

@ -43,6 +43,9 @@ func validatePath(path, workspace string, restrict bool) (string, error) {
if !isWithinWorkspace(resolved, workspaceReal) {
return "", fmt.Errorf("access denied: symlink resolves outside workspace")
}
// Return the resolved path to prevent TOCTOU race
// the caller operates on the validated target directly.
absPath = resolved
} else if os.IsNotExist(err) {
if parentResolved, err := resolveExistingAncestor(filepath.Dir(absPath)); err == nil {
if !isWithinWorkspace(parentResolved, workspaceReal) {