Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 24, 2025

This PR addresses critical security vulnerabilities by implementing a safe demo cloning script with comprehensive protection against dangerous directory removal operations.

Overview

The clone-demo.sh script provides a secure way to clone and set up onchain testkit demo projects while preventing catastrophic system damage from potentially dangerous rm -rf commands.

Key Features

Enhanced Portability

  • Uses #!/usr/bin/env bash shebang for cross-platform compatibility
  • Supports both npm and yarn package managers
  • Strict error handling with set -euo pipefail

Critical Safety Validation

The script implements multiple layers of protection against dangerous directory operations:

# These operations are safely blocked
./clone-demo.sh -d "/"        # ERROR: Refusing to remove dangerous directory
./clone-demo.sh -d "/home"    # ERROR: Refusing to remove dangerous directory
./clone-demo.sh -d ""         # ERROR: Directory path cannot be empty

Comprehensive Protection

  • System Directory Protection: Blocks removal of critical paths (/, /home, /usr, /bin, /sbin, /etc, /var, /boot, /root, /sys, /proc, /dev, /lib, /lib64, /opt, /mnt, /media, $HOME)
  • Path Normalization: Resolves relative paths and validates both original and absolute paths
  • Interactive Confirmation: Shows both relative and absolute paths before removal operations
  • Input Validation: Prevents empty, whitespace-only, or dangerously short paths

Usage Examples

# Clone the default demo repository
./clone-demo.sh

# Clone with custom directory name
./clone-demo.sh -d my-demo-project

# Clean existing directory and clone (with confirmation)
./clone-demo.sh --clean

# Force clean without prompts (still blocks dangerous paths)
./clone-demo.sh --clean --force

# Clone a specific repository
./clone-demo.sh https://github.com/user/specific-repo.git

# Show all available options
./clone-demo.sh --help

Additional Features

  • Colored Output: User-friendly colored messages for info, warnings, errors, and success
  • Flexible Options: Custom directory names, repository URLs, setup control
  • Error Handling: Graceful error handling with descriptive messages
  • Signal Trapping: Handles script interruption safely
  • Comprehensive Documentation: Built-in help system and README integration

The script maintains all existing functionality while providing robust security measures that prevent accidental system damage, making it safe for developers to use in various environments.

Fixes #15.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@joe10832 joe10832 marked this pull request as ready for review September 24, 2025 07:59
Copilot AI review requested due to automatic review settings September 24, 2025 07:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@joe10832 joe10832 merged commit 18960ab into main Sep 24, 2025
3 checks passed
Copilot AI changed the title [WIP] ## Pull Request Overview /.github/copilot-instructions.md /.github/instructions/**/*.instructions.md **/AGENTS.md /CLAUDE.md /GEMINI.md Implement secure clone-demo.sh script with comprehensive safety measures Sep 24, 2025
Copilot AI requested a review from joe10832 September 24, 2025 08:07
Copy link
Member

@joe10832 joe10832 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