Skip to content

Fix home directory check in shell scripts to handle tilde (~) input#28

Merged
joe10832 merged 3 commits intomainfrom
copilot/fix-2243ea35-7903-4e19-a2de-8d39a867bf6d
Sep 24, 2025
Merged

Fix home directory check in shell scripts to handle tilde (~) input#28
joe10832 merged 3 commits intomainfrom
copilot/fix-2243ea35-7903-4e19-a2de-8d39a867bf6d

Conversation

Copy link
Contributor

Copilot AI commented Sep 24, 2025

Problem

The shell scripts for wallet extension preparation (prepare-phantom.sh, prepare-metamask.sh, prepare-coinbase.sh) had a security vulnerability in their directory validation logic. While they correctly checked for the expanded home directory path using "$TARGET_DIR" == "$HOME", they failed to handle cases where users pass the literal tilde character "~" as an argument.

The shell expands ~ to the full home directory path before the comparison in most contexts, but when passed as a literal string argument to these scripts, the comparison "$TARGET_DIR" == "~" was missing, allowing potentially dangerous operations in the user's home directory.

Solution

Added the missing "$TARGET_DIR" == "~" check to the security validation in all three wallet preparation scripts. The updated condition now properly handles both cases:

Before:

if [[ -z "$TARGET_DIR" || "$TARGET_DIR" == "/" || "$TARGET_DIR" == "$HOME" || "$TARGET_DIR" == "." || "$TARGET_DIR" == ".." ]]; then

After:

if [[ -z "$TARGET_DIR" || "$TARGET_DIR" == "/" || "$TARGET_DIR" == "~" || "$TARGET_DIR" == "$HOME" || "$TARGET_DIR" == "." || "$TARGET_DIR" == ".." ]]; then

Testing

Validated that all scripts now correctly:

  • ✅ Reject "~" input with appropriate error messages
  • ✅ Still reject $HOME directory as expected
  • ✅ Accept safe directories like /tmp/safe-dir
  • ✅ Preserve default behavior when no arguments are provided
  • ✅ Pass all existing linting checks

Files Changed

  • src/cli/prepare-phantom.sh - Added tilde check on line 40
  • src/cli/prepare-metamask.sh - Added tilde check on line 40
  • src/cli/prepare-coinbase.sh - Added tilde check on line 40
  • .gitignore - Added exclusion for e2e/extensions/ directory

This fix ensures consistent security validation across all wallet preparation scripts and prevents potential misuse when users pass tilde characters as directory arguments.

Created from VS Code via the GitHub Pull Request extension.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 24, 2025 09:41
Co-authored-by: joe10832 <103850533+joe10832@users.noreply.github.com>
Co-authored-by: joe10832 <103850533+joe10832@users.noreply.github.com>
Copilot AI changed the title [WIP] Update Home Directory Check in Shell Script Fix home directory check in shell scripts to handle tilde (~) input Sep 24, 2025
Copilot AI requested a review from joe10832 September 24, 2025 09:43
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.

@copilot

@joe10832 joe10832 marked this pull request as ready for review September 24, 2025 11:18
Copilot AI review requested due to automatic review settings September 24, 2025 11:18
@joe10832 joe10832 merged commit c23b296 into main Sep 24, 2025
3 checks passed
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.

Pull Request Overview

This PR fixes a security vulnerability in wallet extension preparation scripts by adding proper validation for the tilde (~) character in directory path checks. The scripts now correctly reject both literal ~ input and expanded home directory paths to prevent dangerous operations.

  • Added "$TARGET_DIR" == "~" check to security validation logic
  • Applied fix consistently across all three wallet preparation scripts
  • Enhanced directory validation to handle both tilde literal and expanded home directory cases

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
src/cli/prepare-phantom.sh Added tilde check to directory validation condition
src/cli/prepare-metamask.sh Added tilde check to directory validation condition
src/cli/prepare-coinbase.sh Added tilde check to directory validation condition

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

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.

2 participants