fix(security): Symlink TOCTOU race condition
This commit is contained in:
parent
213274002a
commit
dd75f0b56e
1 changed files with 3 additions and 0 deletions
|
|
@ -43,6 +43,9 @@ func validatePath(path, workspace string, restrict bool) (string, error) {
|
||||||
if !isWithinWorkspace(resolved, workspaceReal) {
|
if !isWithinWorkspace(resolved, workspaceReal) {
|
||||||
return "", fmt.Errorf("access denied: symlink resolves outside workspace")
|
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) {
|
} else if os.IsNotExist(err) {
|
||||||
if parentResolved, err := resolveExistingAncestor(filepath.Dir(absPath)); err == nil {
|
if parentResolved, err := resolveExistingAncestor(filepath.Dir(absPath)); err == nil {
|
||||||
if !isWithinWorkspace(parentResolved, workspaceReal) {
|
if !isWithinWorkspace(parentResolved, workspaceReal) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue