Skip to content

Improve noexec robustness and security#4

Open
ByteJoseph wants to merge 1 commit into
mainfrom
improvement-refactor-14946949604753884641
Open

Improve noexec robustness and security#4
ByteJoseph wants to merge 1 commit into
mainfrom
improvement-refactor-14946949604753884641

Conversation

@ByteJoseph
Copy link
Copy Markdown
Owner

@ByteJoseph ByteJoseph commented May 31, 2026

This submission introduces several improvements to the noexec tool:

  1. Security: Switched from predictable temporary filenames to mktemp, reducing the risk of collisions and race conditions.
  2. Robustness: Added checks for write permissions to the target directory and specific error messages for missing files or directory inputs.
  3. User Experience: Standardized flag handling with a case statement, adding --help support and improving the --version output.
  4. Installer Improvements: The installation script now checks for necessary dependencies (curl, etc.) and verifies write permissions before attempting installation.
  5. Testing: Introduced a bash-based test suite to ensure core functionality remains stable.
  6. Documentation: Updated the README to include the new help flags.

PR created automatically by Jules for task 14946949604753884641 started by @ByteJoseph

Summary by Sourcery

Improve the noexec installation and CLI experience while adding basic automated tests.

New Features:

  • Add -h/--help flags to noexec alongside existing usage output.

Enhancements:

  • Harden the install.sh script with dependency checks, error handling, and permission validation before installing noexec.
  • Improve user-facing messages during installation and initial usage guidance.

Documentation:

  • Document the new -h/--help usage options in the README help section.

Tests:

  • Introduce a bash-based test script that validates normal execution, help output, and error handling for missing files and directory inputs.

- Refactor `src/noexec` to use `mktemp` for unique temporary filenames.
- Add support for `-h`/`--help` and improve `-v`/`--version` handling in `src/noexec`.
- Implement robust permission and file existence checks.
- Enhance `docs/install.sh` with dependency and write permission checks.
- Add a new test suite in `tests/test_noexec.sh`.
- Update `README.md` to reflect new flags.

Co-authored-by: ByteJoseph <131424720+ByteJoseph@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
noexec Building Building Preview May 31, 2026 2:02pm

@netlify
Copy link
Copy Markdown

netlify Bot commented May 31, 2026

Deploy Preview for noexec ready!

Name Link
🔨 Latest commit f812bed
🔍 Latest deploy log https://app.netlify.com/projects/noexec/deploys/6a1c3f660faca2000846c650
😎 Deploy Preview https://deploy-preview-4--noexec.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 31, 2026

Reviewer's Guide

Strengthens noexec’s security and robustness by hardening temporary file handling, improving CLI flag parsing, enforcing permission and dependency checks in the installer, adding a small bash test suite, and updating documentation for the new behavior.

Flow diagram for the updated noexec installer script

flowchart TD
  A[Start install.sh] --> B[Check required commands
curl dirname command cp chmod rm]
  B -->|missing command| C[Print error and exit]
  B -->|all present| D[Download noexec with curl]
  D -->|download failed| E[Print download error and exit]
  D -->|download ok| F[Find bash_path with command -v bash]
  F -->|bash_path empty| G[Print bash not found
remove file
exit]
  F -->|bash_path found| H[Set dir_name to dirname bash_path]
  H --> I[Check write permission on dir_name]
  I -->|not writable| J[Print permission error
remove file
exit]
  I -->|writable| K[Check if file noexec exists]
  K -->|file missing| L[Print downloaded file not found
exit]
  K -->|file present| M[cp noexec to dir_name/noexec]
  M --> N[chmod +x dir_name/noexec]
  N --> O[Print success message and usage hint]
  O --> P[rm noexec]
  P --> Q[End]
Loading

File-Level Changes

Change Details Files
Harden noexec’s core script for safer temp-file usage and more robust argument handling.
  • Replace predictable temporary filenames with mktemp-based creation to avoid collisions and race conditions.
  • Refactor CLI parsing to use a case-based handler, adding explicit -h/--help support and improving --version output.
  • Add validations for input paths, including explicit checks and error messages for missing files and directory arguments.
  • Improve general error handling and exit codes to fail fast on invalid inputs or unexpected conditions.
src/noexec
Make the installer safer by validating environment, dependencies, and permissions before installation.
  • Enable exit-on-error (set -e) to stop on any installer failure.
  • Check for required commands (curl, dirname, command, cp, chmod, rm) before proceeding, with clear error messages if missing.
  • Download noexec with curl -s, detect download failures, and abort with a descriptive error.
  • Resolve bash’s location via command -v bash, aborting if bash is not found.
  • Verify write permissions on the target directory before copying the binary, aborting and cleaning up if not writable.
  • Improve success messaging to include the fully qualified install path and safer cleanup of the temporary file.
docs/install.sh
Document the new help flags and usage patterns in the README.
  • Clarify that running noexec with no arguments or with -h/--help shows usage information.
  • Add explicit examples for invoking noexec -h and noexec --help in the help section.
README.md
Add a bash-based test suite to validate core noexec behaviors and error handling.
  • Create a fake bin directory with a copied bash and prepend it to PATH to ensure a controlled execution environment.
  • Add tests that verify successful execution of a sample script with arguments through noexec.
  • Add tests that validate --help output includes the expected usage text.
  • Add tests that ensure descriptive error messages for non-existent files and directory inputs.
  • Add cleanup logic to remove temporary scripts, directories, and fake bin artifacts after tests run.
tests/test_noexec.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • In docs/install.sh, consider downloading to a uniquely named temporary file (e.g., via mktemp) rather than a fixed noexec filename in the current directory to avoid clobbering an existing file and to be consistent with the mktemp usage elsewhere.
  • The install script currently hardcodes installation to the directory containing bash; you might want to support an override (e.g., via an environment variable or flag) so users can install to a custom directory without modifying the script.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In docs/install.sh, consider downloading to a uniquely named temporary file (e.g., via mktemp) rather than a fixed `noexec` filename in the current directory to avoid clobbering an existing file and to be consistent with the mktemp usage elsewhere.
- The install script currently hardcodes installation to the directory containing `bash`; you might want to support an override (e.g., via an environment variable or flag) so users can install to a custom directory without modifying the script.

## Individual Comments

### Comment 1
<location path="docs/install.sh" line_range="12-7" />
<code_context>
+done
+
+echo "Downloading noexec..."
+if ! curl -s "https://raw.githubusercontent.com/ByteJoseph/noexec/refs/heads/main/src/noexec" -o noexec; then
+  echo "Error: Failed to download noexec."
+  exit 1
+fi
+
</code_context>
<issue_to_address>
**suggestion:** Consider using curl’s failure flags (e.g., `-fS`) instead of fully suppressing output with `-s`.

`-s` hides curl’s error output, which makes debugging failures harder. A pattern like `curl -fSLo noexec "…"` keeps normal output quiet while still failing on HTTP errors and showing a clear error message on stderr.
</issue_to_address>

### Comment 2
<location path="docs/install.sh" line_range="33-39" />
<code_context>
+
 if [ -f "$file" ]; then
-  
   cp "$file" "$dir_name/$file"
   chmod +x "$dir_name/$file"
-  echo "noexec Installed Successfully"
-  rm "noexec"
+  echo "noexec Installed Successfully to $dir_name/$file"
+  rm "$file"
   echo ""
-  echo "Start using now"
</code_context>
<issue_to_address>
**suggestion:** Use `mv` instead of `cp` followed by `rm` to reduce operations and potential failure modes.

Because the file is only needed in its final location, you can replace the `cp` + `rm` pair with `mv "$file" "$dir_name/$file"`. This simplifies the logic, avoids having two copies briefly, and removes the risk of a leftover file if `rm` fails.

```suggestion
if [ -f "$file" ]; then
  mv "$file" "$dir_name/$file"
  chmod +x "$dir_name/$file"
  echo "noexec Installed Successfully to $dir_name/$file"
  echo ""
  echo "Start using now by typing: noexec"
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread docs/install.sh
for cmd in curl dirname command cp chmod rm; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: Required command '$cmd' not found. Please install it and try again."
exit 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Consider using curl’s failure flags (e.g., -fS) instead of fully suppressing output with -s.

-s hides curl’s error output, which makes debugging failures harder. A pattern like curl -fSLo noexec "…" keeps normal output quiet while still failing on HTTP errors and showing a clear error message on stderr.

Comment thread docs/install.sh
Comment on lines 33 to +39
if [ -f "$file" ]; then

cp "$file" "$dir_name/$file"
chmod +x "$dir_name/$file"
echo "noexec Installed Successfully"
rm "noexec"
echo "noexec Installed Successfully to $dir_name/$file"
rm "$file"
echo ""
echo "Start using now"
noexec
echo "Start using now by typing: noexec"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Use mv instead of cp followed by rm to reduce operations and potential failure modes.

Because the file is only needed in its final location, you can replace the cp + rm pair with mv "$file" "$dir_name/$file". This simplifies the logic, avoids having two copies briefly, and removes the risk of a leftover file if rm fails.

Suggested change
if [ -f "$file" ]; then
cp "$file" "$dir_name/$file"
chmod +x "$dir_name/$file"
echo "noexec Installed Successfully"
rm "noexec"
echo "noexec Installed Successfully to $dir_name/$file"
rm "$file"
echo ""
echo "Start using now"
noexec
echo "Start using now by typing: noexec"
if [ -f "$file" ]; then
mv "$file" "$dir_name/$file"
chmod +x "$dir_name/$file"
echo "noexec Installed Successfully to $dir_name/$file"
echo ""
echo "Start using now by typing: noexec"

Copy link
Copy Markdown
Owner Author

@ByteJoseph ByteJoseph left a comment

Choose a reason for hiding this comment

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

😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant