Skip to content

fix: skip unreadable directories during trust scan#173

Open
antitree wants to merge 1 commit intoalways-further:mainfrom
antitree:fix/trust-scan-unreadable-dirs
Open

fix: skip unreadable directories during trust scan#173
antitree wants to merge 1 commit intoalways-further:mainfrom
antitree:fix/trust-scan-unreadable-dirs

Conversation

@antitree
Copy link
Contributor

Summary

  • The pre-exec trust scanner (find_files_recursive) fatally errors when encountering a directory with restricted permissions (e.g., mode 000)
  • std::fs::read_dir() returns EACCES on such directories, which was propagated as a fatal NonoError::Io via ?, aborting the entire sandbox launch
  • This is inconsistent with the existing handling on line 289 where metadata errors on individual files are gracefully skipped with continue

Fix

  • Handle PermissionDenied errors from read_dir() by logging a debug message and returning Ok(()) (skip the directory)
  • Handle PermissionDenied errors from entry iteration with continue
  • All other I/O errors remain fatal

How to reproduce

# Create a directory with mode 000 somewhere under your working directory
mkdir -p /tmp/test-project/subdir
chmod 000 /tmp/test-project/subdir

# Trust scan hits the unreadable directory and fatally errors
nono run --profile claude-code --workdir /tmp/test-project --allow-cwd -- echo hello
# ERROR: I/O error: Permission denied (os error 13)

# Clean up
chmod 755 /tmp/test-project/subdir

Test plan

  • Added regression test find_instruction_files_skips_unreadable_dirs that creates a mode-000 subdirectory and verifies find_instruction_files() succeeds
  • All 33 existing trust policy tests pass
  • Clippy clean with -D warnings -D clippy::unwrap_used

🤖 Generated with Claude Code

…rror

When find_files_recursive() encounters a directory with restricted
permissions (e.g., mode 000), std::fs::read_dir() returns EACCES.
Previously this was propagated as a fatal NonoError::Io, aborting
the entire pre-exec trust scan and preventing the sandboxed command
from launching.

Now permission-denied errors on read_dir() and entry iteration are
handled gracefully by skipping the inaccessible directory, consistent
with the existing pattern for metadata errors on individual files
(line 289).

Adds a regression test that creates a mode-000 subdirectory and
verifies find_instruction_files() succeeds without error.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Mark <[email protected]>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 stability of the trust scanning mechanism by implementing more resilient error handling for file system access. Previously, encountering directories or files with restricted permissions would cause the entire sandbox launch to fail. The changes ensure that such permission issues are now gracefully skipped, allowing the trust scan to complete successfully while logging debug information about the skipped items, thereby improving the overall robustness of the system.

Highlights

  • Robustness for Trust Scanner: The find_files_recursive function, used by the pre-exec trust scanner, was updated to gracefully handle PermissionDenied errors when encountering unreadable directories or files, preventing fatal errors during sandbox launch.
  • Error Handling Refinement: Permission denied errors from std::fs::read_dir() now result in the directory being skipped with a debug log, and similar errors during directory entry iteration are skipped via continue, aligning with existing graceful error handling for individual file metadata.
  • New Regression Test: A new regression test, find_instruction_files_skips_unreadable_dirs, was added to verify that the trust scanner correctly processes files while skipping unreadable directories without crashing.
Changelog
  • crates/nono/src/trust/policy.rs
    • Modified find_files_recursive to catch PermissionDenied errors from std::fs::read_dir and return Ok(()) after logging a debug message.
    • Modified find_files_recursive to catch PermissionDenied errors during iteration over directory entries and continue to the next entry.
    • Added a new test find_instruction_files_skips_unreadable_dirs to validate the new error handling for unreadable directories.
Activity
  • Added a regression test to ensure unreadable directories are skipped.
  • Verified that all 33 existing trust policy tests continue to pass.
  • Confirmed that the codebase remains Clippy clean with strict warning flags.
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

The pull request effectively addresses the issue of the trust scanner failing when encountering unreadable directories or files due to permission denied errors. The find_files_recursive function now gracefully skips such entries, logging them at a debug level, which significantly improves the robustness of the scan. The addition of a dedicated regression test case, find_instruction_files_skips_unreadable_dirs, thoroughly validates this fix, ensuring that the scanner correctly identifies accessible files while ignoring unreadable ones without aborting the entire process. This change aligns well with the goal of making the scanner more resilient to varying filesystem permissions.

@lukehinds
Copy link
Collaborator

good find @antitree !

One small change would balance things well. The trust policy has three enforcement levels:

  • Audit — allow access, just log it
  • Warn — allow access but log a warning
  • Deny — hard block unsigned/untrusted files (the default which is causing the panic)

What might be useful is if enforcement is Deny, treat an unreadable directory as an error (fail closed). If it's Warn or Audit, skipping with a warning is fine - the user has already opted into a more permissive posture. Should not be much of a change as find_files_recursive already receives the full TrustPolicy (which contains enforcement level).

wdyt?

@lukehinds
Copy link
Collaborator

@antitree just on previous comment, we can follow up with that - then we just have a rust format simple fix and we can land.

@lukehinds lukehinds added the bug Something isn't working label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants