Skip to content

fix: harden the narinfo route pattern#841

Merged
kalbasit merged 1 commit intomainfrom
02-11-security_harden_the_narinfo_route_pattern
Feb 12, 2026
Merged

fix: harden the narinfo route pattern#841
kalbasit merged 1 commit intomainfrom
02-11-security_harden_the_narinfo_route_pattern

Conversation

@kalbasit
Copy link
Owner

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.

@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 enhances the security of the narinfo endpoint by implementing a stricter regular expression for hash validation directly within the route definition. This change ensures that incoming requests for narinfo files adhere to the latest upstream specifications, thereby preventing malformed or malicious requests from reaching the handler and improving the overall robustness of the server's request handling.

Highlights

  • Narinfo Route Hardening: The narinfo route pattern has been updated to align with the upstream definition in Add Nix32 encoding documentation NixOS/nix#15004, ensuring that only requests matching this specific pattern are allowed.
  • Validation Shift: The hash validation logic for narinfo requests has been moved from an explicit helper.IsValidHash check within the handler to the routing pattern itself, making the route definition more robust.
  • Test Updates: Related test cases in security_test.go were adjusted to reflect the new validation behavior, including the removal of a redundant valid hash test and an update to a path traversal test's expected status.
Changelog
  • pkg/server/security_test.go
    • Removed a test case for a valid 52-character narinfo hash.
    • Modified a path traversal test case to use a different malicious path and expect a StatusNotFound instead of StatusBadRequest.
  • pkg/server/server.go
    • Imported the narinfo package.
    • Updated the routeNarInfo constant to use the narinfo.NarInfoHashPattern for stricter hash validation.
    • Removed the explicit helper.IsValidHash check from the getNarInfo handler, as validation is now handled by the route pattern.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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.

@dosubot
Copy link

dosubot bot commented Feb 11, 2026

Related Documentation

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

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added the go Pull requests that update go code label Feb 11, 2026
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 security of the narinfo route by enforcing a stricter pattern for the hash at the router level. This is a good improvement. The associated test changes are mostly correct, though a test name could be more descriptive. I've also noted an opportunity for further cleanup in related handlers to maintain consistency with the changes made.

@kalbasit kalbasit force-pushed the 02-11-security_harden_the_narinfo_route_pattern branch from ad39796 to a3fc32b Compare February 11, 2026 19:07
@kalbasit kalbasit force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch from af8d25f to abf888a Compare February 11, 2026 19:07
@kalbasit kalbasit force-pushed the 02-11-security_harden_the_narinfo_route_pattern branch from a3fc32b to a9db580 Compare February 11, 2026 19:15
@kalbasit kalbasit force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch from abf888a to 72c518e Compare February 11, 2026 19:15
@kalbasit kalbasit force-pushed the 02-11-security_harden_the_narinfo_route_pattern branch from a9db580 to f516d91 Compare February 11, 2026 19:30
@kalbasit kalbasit force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch from 72c518e to 0cc36f7 Compare February 11, 2026 19:30
@kalbasit kalbasit force-pushed the 02-11-security_harden_the_narinfo_route_pattern branch from f516d91 to a5bdc92 Compare February 11, 2026 19:31
@kalbasit kalbasit force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch 2 times, most recently from 15b5c18 to 714c33b Compare February 11, 2026 20:25
@kalbasit kalbasit force-pushed the 02-11-security_harden_the_narinfo_route_pattern branch from a5bdc92 to e276ea3 Compare February 11, 2026 20:25
@kalbasit kalbasit force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch from 714c33b to d7e4ebc Compare February 11, 2026 21:03
@kalbasit kalbasit force-pushed the 02-11-security_harden_the_narinfo_route_pattern branch from e276ea3 to ad68338 Compare February 11, 2026 21:03
@kalbasit kalbasit force-pushed the 02-11-security_harden_the_narinfo_route_pattern branch from ad68338 to e6e447c Compare February 12, 2026 01:14
@kalbasit kalbasit force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch from d7e4ebc to 05cd73e Compare February 12, 2026 01:14
@kalbasit kalbasit added backport release-0.8 Backport PR automatically labels Feb 12, 2026
Base automatically changed from 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation to main February 12, 2026 01:26
@dosubot dosubot bot removed the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 12, 2026
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Feb 12, 2026
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.
@kalbasit kalbasit changed the title security: harden the narinfo route pattern fix: harden the narinfo route pattern Feb 12, 2026
@kalbasit kalbasit force-pushed the 02-11-security_harden_the_narinfo_route_pattern branch from e6e447c to be06e36 Compare February 12, 2026 01:41
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 12, 2026
@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 3.96%. Comparing base (91945f3) to head (be06e36).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #841   +/-   ##
=====================================
  Coverage   3.96%   3.96%           
=====================================
  Files          6       6           
  Lines        429     429           
=====================================
  Hits          17      17           
  Misses       409     409           
  Partials       3       3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalbasit kalbasit merged commit e91ec45 into main Feb 12, 2026
17 checks passed
@kalbasit kalbasit deleted the 02-11-security_harden_the_narinfo_route_pattern branch February 12, 2026 01:52
kalbasit added a commit that referenced this pull request Feb 12, 2026
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
Copy link
Owner Author

Successfully created backport PR for release-0.8:

kalbasit added a commit that referenced this pull request Feb 12, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release-0.8 Backport PR automatically 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