Skip to content

Commit 88ecfdd

Browse files
committed
fix(security): O_NOFOLLOW for searchFilesTool.searchContent and glob tool binary-skip
The searchFilesTool.searchContent() and the glob tool's binary-skip path opened files with plain os.Open() — no O_NOFOLLOW. An attacker with write access under the search root could exploit the TOCTOU window between the filepath.Walk check and the actual open. Both now use os.OpenFile(path, os.O_RDONLY|syscall.O_NOFOLLOW, 0), consistent with readFileTool, batchReadTool, and all other file tools. Fixes H1 from security audit.
1 parent 3d2c58f commit 88ecfdd

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

cmd/odek/file_tool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func (t *searchFilesTool) searchContent(args searchFilesArgs) (string, error) {
390390
}
391391

392392
// Skip binary files — single open for check then search
393-
f, err := os.Open(path)
393+
f, err := os.OpenFile(path, os.O_RDONLY|syscall.O_NOFOLLOW, 0)
394394
if err != nil {
395395
return nil
396396
}

cmd/odek/perf_tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ func (t *multiGrepTool) searchPattern(pattern, root, fileGlob string, limit int)
10981098
}
10991099
}
11001100

1101-
f, err := os.Open(path)
1101+
f, err := os.OpenFile(path, os.O_RDONLY|syscall.O_NOFOLLOW, 0)
11021102
if err != nil {
11031103
return nil
11041104
}

0 commit comments

Comments
 (0)