fix: validate backport branch name#9548
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR enhances security by validating backport branch names in the GitHub workflow before setting them as environment variables. The validation prevents potential command injection by ensuring branch names contain only safe characters while still allowing dotted release branches like release/v0.53.1.
- Added validation for extracted branch names using regex pattern matching
- Added error handling to exit immediately when invalid or empty branch names are detected
- Improved shell scripting practices with proper variable quoting
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| BRANCH_NAME=$(echo $COMMENT_BODY | grep -oE '@aqua-bot backport\s+(\S+)' | awk '{print $3}') | ||
| echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | ||
| BRANCH_NAME=$(echo "$COMMENT_BODY" | grep -oE '@aqua-bot backport\s+(\S+)' | awk '{print $3}') | ||
| if [[ -z "$BRANCH_NAME" || ! "$BRANCH_NAME" =~ ^[A-Za-z0-9._/-]+$ ]]; then |
There was a problem hiding this comment.
The regex pattern allows dots which could enable path traversal attacks with patterns like '../'. Consider restricting dots to only appear in specific contexts (e.g., version numbers) or use a more restrictive pattern like ^[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$ to prevent directory traversal.
| if [[ -z "$BRANCH_NAME" || ! "$BRANCH_NAME" =~ ^[A-Za-z0-9._/-]+$ ]]; then | |
| if [[ -z "$BRANCH_NAME" || ! "$BRANCH_NAME" =~ ^[A-Za-z0-9._-]+(/[A-Za-z0-9._-]+)*$ ]]; then |
Description
GITHUB_ENVrelease/v0.53.1Checklist