-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
We are currently suppressing gosec G304 warnings (Potential file inclusion via variable) using //nolint:gosec comments in several adapters. With our upgrade to Go 1.25+, we can now leverage the os.Root API introduced in Go 1.24 to enforce secure, directory-scoped file access.
Using os.Root guarantees that file operations cannot escape the intended directory, effectively mitigating path traversal vulnerabilities at the filesystem level. This allows us to remove the linter suppressions and improve the actual security posture of the application.
Note: This refactor applies to file access (G304). It does not apply to command execution (G204) in shell/executor.go, as os.Root does not support executing binaries.
Goals
- Refactor
internal/adapters/casto useos.OpenRootfor the CAS store directory. - Refactor
internal/adapters/nixto useos.OpenRootfor the NixHub cache directory. - Refactor
internal/adapters/configto safely load configuration files relative to the project root. - Remove
//nolint:gosecdirectives in the refactored files.
Implementation Plan
1. CAS Store (internal/adapters/cas/store.go)
- Update
Storestruct to hold*os.Rootinstead of a string path. - In
NewStore, useos.OpenRootto open the.same/storedirectory. - Replace
os.ReadFileandos.WriteFilecalls withs.root.ReadFileands.root.WriteFile. - Remove path joining logic that constructs absolute paths for artifacts; use relative names with the root handle.
2. Nix Resolver (internal/adapters/nix/resolver.go)
- Update
Resolverto hold*os.Rootfor the cache directory. - Replace
atomicWriteFileandloadFromCachelogic to operate on the root handle. - Ensure the root is properly closed on shutdown if necessary.
3. Config Loader (internal/adapters/config/loader.go)
- When loading a project, open the project directory using
os.OpenRoot. - Load
same.yamlusing the root handle to prevent a malicious config from pointinginputfields to sensitive system files outside the project scope (e.g.,../../../etc/passwd).
Acceptance Criteria
-
internal/adapters/cas/store.gono longer requires//nolint:gosecfor file reads/writes. -
internal/adapters/nix/resolver.gono longer requires//nolint:gosec. -
internal/adapters/config/loader.gousesos.Rootfor file operations. - All existing tests pass (
nix develop -c go test ./cli/...). -
golangci-lintpasses without the removed suppressions.
Metadata
Metadata
Assignees
Labels
No labels