feat: only allow paths to be in working directory#572
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements security improvements for file path handling by restricting file access to a working directory and preventing path traversal attacks. The changes add a new function to safely resolve file paths within a specified working directory with default-deny behavior for path escapes.
- Added
GetBlobInWorkingDirectoryfunction with working directory validation - Implemented
ensureWdOrPathhelper function usingos.OpenInRootfor secure path resolution - Added comprehensive test coverage for various path scenarios including valid and invalid cases
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| bindings/go/blob/filesystem/file.go | Adds new functions for working directory-constrained file access |
| bindings/go/blob/filesystem/file_test.go | Adds test coverage for working directory validation scenarios |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
6cdf89c to
845e14a
Compare
717c4a6 to
1c817f1
Compare
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
1c817f1 to
1dd6726
Compare
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
fabianburth
left a comment
There was a problem hiding this comment.
Looks good now!
I'd like to propose two more tiny changes (which are arguably kind of nits), then we are ready to merge.
Co-authored-by: Fabian Burth <fabian.burth@sap.com> Update bindings/go/blob/filesystem/file_test.go Co-authored-by: Fabian Burth <fabian.burth@sap.com> Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
06c8a30 to
c92da96
Compare
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
fabianburth
left a comment
There was a problem hiding this comment.
Please wrap the errors before returning. This makes it way easier to search for the concrete places in code later.
56bf739 to
bd2b842
Compare
Signed-off-by: Matthias Bruns <git@matthiasbruns.com>
bd2b842 to
7cdd838
Compare
| // If the path is absolute, it checks if the path is valid within the working directory. | ||
| // If the path is relative, it resolves it against the working directory and prevents escaping the working directory. | ||
| // If the path cannot be resolved or is invalid, it returns an error. | ||
| func EnsurePathInWorkingDirectory(path, workingDirectory string) (_ string, err error) { |
There was a problem hiding this comment.
why was this function exported, is it needed elsewhere?? IMO our blob package should deal with blobs and not expose functions on filepaths.
Based on the comment #557 (comment)
What this PR does / why we need it
Resolve file/dir inputs relative to the constructor file by wiring a filesystem working directory through input methods; default-deny path escapes with an explicit opt-out.
Changes (high level):
Which issue(s) this PR fixes
Fixes #565