Skip to content

Commit 3bb3572

Browse files
committed
refactor: improve alias validation to enhance security and error messaging
1 parent 2316ed2 commit 3bb3572

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

phpvm.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,16 +2740,17 @@ phpvm_alias() {
27402740
return "$PHPVM_EXIT_INVALID_ARG"
27412741
fi
27422742

2743-
# Validate version format BEFORE using it in path check (security)
2744-
# This prevents path traversal attacks with malicious version strings
2745-
if ! validate_php_version "$version"; then
2746-
phpvm_err "Invalid PHP version format: $version"
2743+
# Check if target is an alias BEFORE version validation
2744+
# This gives a better error message for alias chains
2745+
# Use phpvm_validate_alias_name first to ensure safe file access
2746+
if phpvm_validate_alias_name "$version" 2> /dev/null && [ -f "$PHPVM_DIR/alias/$version" ]; then
2747+
phpvm_err "Alias target '$version' is itself an alias. Please point aliases directly to a PHP version."
27472748
return "$PHPVM_EXIT_INVALID_ARG"
27482749
fi
27492750

2750-
# Now safe to check if target is an alias (version format is validated)
2751-
if [ -f "$PHPVM_DIR/alias/$version" ]; then
2752-
phpvm_err "Alias target '$version' is itself an alias. Please point aliases directly to a PHP version."
2751+
# Validate version format (security: prevents path traversal attacks)
2752+
if ! validate_php_version "$version"; then
2753+
phpvm_err "Invalid PHP version format: $version"
27532754
return "$PHPVM_EXIT_INVALID_ARG"
27542755
fi
27552756

0 commit comments

Comments
 (0)