-
Notifications
You must be signed in to change notification settings - Fork 94
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
// isAllowedDir checks if the given path is in the list of allowed directories. | ||
// It returns true if the path is allowed, false otherwise. | ||
// If the path does not exist, it logs a warning and returns false. | ||
// It also checks if the path is a file, in which case it checks the directory of the file. |
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.
I think the part about if path doesn't exist might cause issues when this PR goes in #1134. From my understanding a directory that does not exist can be refrenced
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.
Removed that portion so I'll update the comment, thanks!
expected []string | ||
}{ | ||
{ | ||
name: "Empty path", |
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 update the format of the test names to
Test 1: Empty path
// 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?
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
)