-
Notifications
You must be signed in to change notification settings - Fork 95
Add validation to allowed directories on config load #1144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
internal/config/types.go
Outdated
// It returns true if the path is allowed, false otherwise. | ||
// If the path is allowed but does not exist, it also logs a warning. | ||
// It also checks if the path is a file, in which case it checks the directory of the file. | ||
func isAllowedDir(path string, allowedDirs []string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you pass the context into this function as well so that we can use it in the log statements?
directoryPath := path | ||
isFilePath, err := regexp.MatchString(`\.(\w+)$`, directoryPath) | ||
if err != nil { | ||
slog.Error("Error matching path", "path", directoryPath, "error", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a warning?
// It also checks if the path is a file, in which case it checks the directory of the file. | ||
func isAllowedDir(path string, allowedDirs []string) (bool, error) { | ||
if len(allowedDirs) == 0 { | ||
slog.Warn("No allowed directories configured") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are returning an error then there is no need for this log message as the calling function will probably log the error anyways
directoryPath := path | ||
isFilePath, err := regexp.MatchString(`\.(\w+)$`, directoryPath) | ||
if err != nil { | ||
slog.Error("Error matching path", "path", directoryPath, "error", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as comment above
Proposed changes
Adds some validation of paths when loading the allowed directories.
Allowed paths must:
.
,..
,etc)Any files not satisfying this criteria will be ignored, and logged at WARN level.
When checking if a path is allowed using
isAllowedDir
, we will now check if the path exists and if it does we will perform a symlink check. Any symlinks will be logged and the function will return false.Checklist
Before creating a PR, run through this checklist and mark each as complete.
CONTRIBUTING
documentmake install-tools
and have attached any dependency changes to this pull requestREADME.md
)