Skip to content

fix: harden the narinfo route pattern [backport #841]#854

Merged
kalbasit merged 1 commit intorelease-0.8from
backport-841-to-release-0.8
Feb 12, 2026
Merged

fix: harden the narinfo route pattern [backport #841]#854
kalbasit merged 1 commit intorelease-0.8from
backport-841-to-release-0.8

Conversation

@kalbasit
Copy link
Owner

Bot-based backport to release-0.8, triggered by a label in #841.

The narinfo hash was updated in #840 to reflect the upstream definition
in NixOS/nix#15004 and so the server should only allow narinfo requests
that match this pattern.

The narinfo hash was updated in #840 to reflect the upstream definition
in NixOS/nix#15004 and so the server should only allow narinfo requests
that match this pattern.

(cherry picked from commit e91ec45)
@kalbasit kalbasit enabled auto-merge (squash) February 12, 2026 01:52
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working go Pull requests that update go code labels Feb 12, 2026
@dosubot
Copy link

dosubot bot commented Feb 12, 2026

Related Documentation

Checked 7 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 strengthens the narinfo route pattern to enforce a more precise hash format, consistent with upstream Nix specifications. This change improves the robustness of the server's request handling by integrating hash validation directly into the routing mechanism, thereby removing the need for a separate validation step in the handler. The associated test suite has been updated to reflect these enhanced security measures.

Highlights

  • Stricter Narinfo Route Pattern: Updated the narinfo route pattern in pkg/server/server.go to use a more stringent narinfo.HashPattern, aligning with upstream Nix definitions for enhanced security and validation.
  • Removed Redundant Hash Validation: Eliminated the explicit helper.IsValidHash check within the getNarInfo handler in pkg/server/server.go, as hash validation is now handled directly by the updated route pattern.
  • Updated Security Test Cases: Adjusted test cases in pkg/server/security_test.go to reflect the new narinfo hash validation logic, including removing an outdated valid hash test and updating expected status codes for malicious path attempts.
Changelog
  • pkg/server/security_test.go
    • Removed a test case for a 52-character narinfo hash that is no longer considered valid under the new pattern.
    • Modified a path traversal test case to expect a StatusNotFound response instead of StatusBadRequest due to the updated routing logic.
  • pkg/server/server.go
    • Imported the narinfo package to access the new hash pattern.
    • Updated the routeNarInfo constant to incorporate narinfo.HashPattern for stricter URL routing.
    • Removed the helper.IsValidHash check from the getNarInfo handler, as validation is now performed by the route pattern.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request hardens the narinfo route pattern to align with the upstream Nix definition, which is a good security and correctness improvement. The route now uses a stricter regular expression to validate the hash format at the routing layer, simplifying the handler logic by removing now-redundant validation. The tests have been updated to reflect these changes. I've identified a minor consistency issue where the validation removal was not applied to all relevant handlers, and I've left a comment with a suggestion to address it.

@kalbasit kalbasit disabled auto-merge February 12, 2026 02:04
@kalbasit kalbasit merged commit 5b922b8 into release-0.8 Feb 12, 2026
14 checks passed
@kalbasit kalbasit deleted the backport-841-to-release-0.8 branch February 12, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant