Skip to content

fix: harden the narinfo hash validation#840

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

fix: harden the narinfo hash validation#840
kalbasit merged 1 commit intomainfrom
02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation

Conversation

@kalbasit
Copy link
Owner

This commit hardens the narinfo hash validation to strictly enforce the Nix32
encoding specification:

  • Enforce exactly 32-character hash length (previously allowed any length)
  • Restrict to valid Nix32 alphabet: 0-9, a-d, f-n, p-s, v-z (previously
    allowed any lowercase letter and digit)
  • Explicitly reject forbidden characters: e, o, u, t
  • Reject uppercase letters and special characters

Added 18 comprehensive test cases covering:

  • Valid hashes with different character combinations
  • Invalid hashes with forbidden characters
  • Invalid hashes with wrong lengths
  • Invalid hashes with special characters and uppercase letters

This ensures that only valid Nix32 hashes are accepted, preventing potential
data corruption or compatibility issues in the narinfo processing pipeline.

@dosubot dosubot bot added enhancement New feature or request go Pull requests that update go code labels Feb 11, 2026
@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 significantly enhances the robustness of narinfo hash validation by implementing strict adherence to the Nix32 encoding specification. The changes prevent potential data corruption or compatibility issues by ensuring that only correctly formatted hashes are processed, thereby improving the overall reliability of the system's data handling.

Highlights

  • Stricter Hash Validation: The ValidateHash function now strictly enforces the Nix32 encoding specification for narinfo hashes, ensuring compliance with length and character set requirements.
  • Nix32 Alphabet Enforcement: The validation now restricts hashes to the specific Nix32 alphabet (0-9, a-d, f-n, p-s, v-z) and explicitly rejects forbidden characters like 'e', 'o', 'u', and 't'.
  • Length and Case Sensitivity: Hashes are now required to be exactly 32 characters long, and uppercase letters or special characters are explicitly rejected.
  • Comprehensive Test Coverage: Eighteen new test cases have been added to thoroughly cover valid and invalid hash scenarios, including correct formats, forbidden characters, incorrect lengths, and special characters.
Changelog
  • pkg/narinfo/hash.go
    • Updated the narInfoHashPattern regular expression to enforce Nix32 encoding rules, including a fixed length of 32 characters and a restricted character set.
    • Added detailed comments to the ValidateHash function explaining the new validation requirements.
  • pkg/narinfo/hash_test.go
    • Added a new test file hash_test.go to provide comprehensive unit tests for the ValidateHash function.
    • Included 18 new test cases covering valid Nix32 hashes, hashes with forbidden characters, incorrect lengths, uppercase letters, and special characters.
Activity
  • No human activity has been recorded on 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

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 significantly improves the narinfo hash validation by enforcing strict Nix32 encoding rules for character set and length, which is a great improvement over the previous, more permissive validation. The addition of a comprehensive test suite with numerous cases is excellent, covering a wide range of valid and invalid inputs to ensure the new logic is robust. The changes are well-implemented. I have one minor suggestion to improve comment clarity.

@kalbasit kalbasit force-pushed the fix-test-data-generation-and-skip-signature-verification branch from 6cde063 to 6ffbcd0 Compare February 11, 2026 17:49
@kalbasit kalbasit force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch from 8520594 to d14dbe2 Compare February 11, 2026 17:49
kalbasit added a commit that referenced this pull request Feb 11, 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 force-pushed the fix-test-data-generation-and-skip-signature-verification branch from 6ffbcd0 to b226ff0 Compare February 11, 2026 18:37
@kalbasit kalbasit force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch from d14dbe2 to af8d25f Compare February 11, 2026 18:37
kalbasit added a commit that referenced this pull request Feb 11, 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 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 added a commit that referenced this pull request Feb 11, 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 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 fix-test-data-generation-and-skip-signature-verification branch from b226ff0 to ebe277b Compare February 11, 2026 19:15
Base automatically changed from fix-test-data-generation-and-skip-signature-verification to main February 11, 2026 19:29
kalbasit added a commit that referenced this pull request Feb 11, 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 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 added a commit that referenced this pull request Feb 11, 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 force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch from 926ba30 to 15b5c18 Compare February 11, 2026 19:31
@kalbasit kalbasit changed the title test: add comprehensive ValidateHash tests with strict Nix32 validation security: harden the narinfo hash validation Feb 11, 2026
@kalbasit kalbasit changed the title security: harden the narinfo hash validation fix: harden the narinfo hash validation Feb 11, 2026
@kalbasit kalbasit enabled auto-merge (squash) February 11, 2026 19:34
kalbasit added a commit that referenced this pull request Feb 11, 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 force-pushed the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch from 15b5c18 to 714c33b Compare February 11, 2026 20:25
kalbasit added a commit that referenced this pull request Feb 11, 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 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
This commit hardens the narinfo hash validation to strictly enforce the Nix32
encoding specification:

- Enforce exactly 32-character hash length (previously allowed any length)
- Restrict to valid Nix32 alphabet: 0-9, a-d, f-n, p-s, v-z (previously
  allowed any lowercase letter and digit)
- Explicitly reject forbidden characters: e, o, u, t
- Reject uppercase letters and special characters

Added 18 comprehensive test cases covering:
- Valid hashes with different character combinations
- Invalid hashes with forbidden characters
- Invalid hashes with wrong lengths
- Invalid hashes with special characters and uppercase letters

This ensures that only valid Nix32 hashes are accepted, preventing potential
data corruption or compatibility issues in the narinfo processing pipeline.
@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 and removed backport release-0.8 Backport PR automatically 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 (3d4d257) to head (05cd73e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #840   +/-   ##
=====================================
  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 91945f3 into main Feb 12, 2026
18 checks passed
@kalbasit kalbasit deleted the 02-11-test_add_comprehensive_validatehash_tests_with_strict_nix32_validation branch February 12, 2026 01:26
@kalbasit kalbasit added backport release-0.8 Backport PR automatically labels Feb 12, 2026
@kalbasit
Copy link
Owner Author

Backport failed for release-0.8, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin release-0.8
git worktree add -d .worktree/backport-840-to-release-0.8 origin/release-0.8
cd .worktree/backport-840-to-release-0.8
git switch --create backport-840-to-release-0.8
git cherry-pick -x 91945f3df2fadd881c7dc0cc883b327458ee88a0

1 similar comment
@kalbasit
Copy link
Owner Author

Backport failed for release-0.8, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin release-0.8
git worktree add -d .worktree/backport-840-to-release-0.8 origin/release-0.8
cd .worktree/backport-840-to-release-0.8
git switch --create backport-840-to-release-0.8
git cherry-pick -x 91945f3df2fadd881c7dc0cc883b327458ee88a0

kalbasit added a commit that referenced this pull request Feb 12, 2026
This commit hardens the narinfo hash validation to strictly enforce the Nix32
encoding specification:

- Enforce exactly 32-character hash length (previously allowed any length)
- Restrict to valid Nix32 alphabet: 0-9, a-d, f-n, p-s, v-z (previously
  allowed any lowercase letter and digit)
- Explicitly reject forbidden characters: e, o, u, t
- Reject uppercase letters and special characters

Added 18 comprehensive test cases covering:
- Valid hashes with different character combinations
- Invalid hashes with forbidden characters
- Invalid hashes with wrong lengths
- Invalid hashes with special characters and uppercase letters

This ensures that only valid Nix32 hashes are accepted, preventing potential
data corruption or compatibility issues in the narinfo processing pipeline.

(cherry picked from commit 91945f3)
kalbasit added a commit that referenced this pull request Feb 12, 2026
This commit hardens the narinfo hash validation to strictly enforce the
Nix32 encoding specification:

- Enforce exactly 32-character hash length (previously allowed any
length)
- Restrict to valid Nix32 alphabet: 0-9, a-d, f-n, p-s, v-z (previously
allowed any lowercase letter and digit)
- Explicitly reject forbidden characters: e, o, u, t
- Reject uppercase letters and special characters

Added 18 comprehensive test cases covering:
- Valid hashes with different character combinations
- Invalid hashes with forbidden characters
- Invalid hashes with wrong lengths
- Invalid hashes with special characters and uppercase letters

This ensures that only valid Nix32 hashes are accepted, preventing
potential data corruption or compatibility issues in the narinfo
processing pipeline.

(cherry picked from commit 91945f3)
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.
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 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 enhancement New feature or request go Pull requests that update go code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant