fix: Apply NAR URL normalization in storage layer#837
Conversation
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 standardizes how NAR (Nix Archive) URLs are processed within the storage layer. By applying a normalization step to NAR URLs before they are used for file path operations, the system ensures that NARs are consistently stored and retrieved. This change makes both local and S3 storage backends robust against variations in NAR URL formatting, specifically addressing cases where URLs might include an embedded narinfo hash prefix. Highlights
Changelog
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 implements NAR URL normalization across local and S3 storage backends to ensure consistent storage and retrieval. However, it introduces a critical path traversal vulnerability because the Normalize() function lacks proper output validation. This affects both local and S3 storage backends, allowing an attacker to read and write arbitrary files or S3 objects, potentially leading to Remote Code Execution. The Normalize function in pkg/nar/url.go must be fixed to prevent it from returning path traversal payloads.
28217db to
4c9ec75
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly adds NAR URL normalization in the local and S3 storage layers to handle URLs with an embedded narinfo hash prefix. However, the implementation introduces a critical path traversal vulnerability. The new nar.URL.Normalize() function has a flawed 'fail-open' sanitization mechanism, returning malicious input when a path traversal is detected. This allows an attacker to read, write, or delete arbitrary files on the local filesystem or in the S3 bucket. The Normalize function must be fixed to fail safely. Additionally, my feedback suggests improving code clarity by chaining method calls and addressing duplicated logic in the local storage backend for better maintainability.
fd85478 to
7800e7c
Compare
Normalize NAR URLs before file path operations in both local and S3 storage backends. This ensures consistent storage and retrieval regardless of whether the NAR URL contains an embedded narinfo hash prefix. Changes: - pkg/storage/local/local.go: Add URL.Normalize() in HasNar, GetNar, PutNar, DeleteNar - pkg/storage/s3/s3.go: Add URL.Normalize() in narPath method This ensures that NARs are stored and retrieved using the normalized hash, making the storage layer agnostic to whether the input URL has a prefix. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
7800e7c to
0b7597e
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #837 +/- ##
=======================================
Coverage 85.41% 85.41%
=======================================
Files 2 2
Lines 480 480
=======================================
Hits 410 410
Misses 65 65
Partials 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Normalize NAR URLs before file path operations in both local and S3 storage backends. This ensures consistent storage and retrieval regardless of whether the NAR URL contains an embedded narinfo hash prefix. Changes: - pkg/storage/local/local.go: Add URL.Normalize() in HasNar, GetNar, PutNar, DeleteNar - pkg/storage/s3/s3.go: Add URL.Normalize() in narPath method This ensures that NARs are stored and retrieved using the normalized hash, making the storage layer agnostic to whether the input URL has a prefix. Part of #806 --------- Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> (cherry picked from commit c6e9967)
Normalize NAR URLs before file path operations in both local and S3 storage backends. This ensures consistent storage and retrieval regardless of whether the NAR URL contains an embedded narinfo hash prefix. Changes: - pkg/storage/local/local.go: Add URL.Normalize() in HasNar, GetNar, PutNar, DeleteNar - pkg/storage/s3/s3.go: Add URL.Normalize() in narPath method This ensures that NARs are stored and retrieved using the normalized hash, making the storage layer agnostic to whether the input URL has a prefix. Part of #806 --------- Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> (cherry picked from commit c6e9967)

Normalize NAR URLs before file path operations in both local and S3 storage
backends. This ensures consistent storage and retrieval regardless of whether
the NAR URL contains an embedded narinfo hash prefix.
Changes:
This ensures that NARs are stored and retrieved using the normalized hash,
making the storage layer agnostic to whether the input URL has a prefix.
Part of #806
Co-Authored-By: Claude Haiku 4.5 noreply@anthropic.com