Repository navigation
feat: remove empty directories after file deletion in local storage [backport #722] - #725
Conversation
This change addresses a path injection vulnerability (alert #7) where unvalidated hashes could be used to construct file paths, potentially allowing access to arbitrary files. Hash validation has been added to `pkg/helper/filepath.go` using a regex that ensures hashes only contain alphanumeric characters. The return signatures of `NarInfoFilePath` and `NarFilePath` have been updated to return an error if the hash is invalid. All call sites in `pkg/storage/local`, `pkg/storage/s3`, and `pkg/nar` have been updated to handle these errors. A validation helper `ValidateHash` and a new error `ErrInvalidHash` were introduced in `pkg/helper/filepath.go` to support these checks. (cherry picked from commit 2eb0a8c)
Summary of ChangesHello @kalbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the application's security posture by introducing robust validation for hash inputs used in file path generation. By converting previously panic-inducing or unchecked path constructions into error-returning functions, it ensures that invalid or malicious hash inputs are caught and handled gracefully across various storage operations, preventing potential path injection attacks. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces an important security fix by validating hashes used to construct file paths, effectively preventing a path injection vulnerability. The changes are well-implemented, replacing panics with proper error handling and updating all call sites accordingly. The tests have also been updated to reflect these changes and include cases for invalid hashes. I've included a low-priority suggestion regarding code duplication, keeping in mind the repository's guidelines on acceptable duplication. Overall, this is a great improvement.
This change addresses a path injection vulnerability (alert #7) where unvalidated hashes could be used to construct file paths, potentially allowing access to arbitrary files.
Hash validation has been added to
pkg/helper/filepath.gousing a regex that ensures hashes only contain alphanumeric characters.The return signatures of
NarInfoFilePathandNarFilePathhave been updated to return an error if the hash is invalid. All call sites inpkg/storage/local,pkg/storage/s3, andpkg/narhave been updated to handle these errors.A validation helper
ValidateHashand a new errorErrInvalidHashwere introduced inpkg/helper/filepath.goto support these checks.(cherry picked from commit 2eb0a8c)