Skip to content

Commit 311f54e

Browse files
committed
harden inputs against injection
1 parent 146f3c7 commit 311f54e

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

action.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,24 @@ runs:
3131
persist-credentials: false
3232
lfs: ${{ inputs.git_lfs }}
3333
- name: Validate inputs
34+
env:
35+
GITLAB_URL: ${{ inputs.gitlab_url }}
36+
USERNAME: ${{ inputs.username }}
37+
GITLAB_PAT: ${{ inputs.gitlab_pat }}
3438
run: |
3539
errors=()
3640
37-
if [[ -z "${{ inputs.gitlab_url }}" ]]; then
41+
if [[ -z "$GITLAB_URL" ]]; then
3842
errors+=("gitlab_url is not set. Please add GITLAB_URL to your repository secrets.")
39-
elif [[ ! "${{ inputs.gitlab_url }}" =~ ^https?://[^/]+/.+ ]]; then
43+
elif [[ ! "$GITLAB_URL" =~ ^https?://[^/]+/.+ ]]; then
4044
errors+=("gitlab_url format is invalid. Expected: https://gitlab.com/user/repo.git")
4145
fi
4246
43-
if [[ -z "${{ inputs.username }}" ]]; then
47+
if [[ -z "$USERNAME" ]]; then
4448
errors+=("username is not set. Please add USERNAME to your repository secrets.")
4549
fi
4650
47-
if [[ -z "${{ inputs.gitlab_pat }}" ]]; then
51+
if [[ -z "$GITLAB_PAT" ]]; then
4852
errors+=("gitlab_pat is not set. Please add GITLAB_PAT to your repository secrets.")
4953
fi
5054
@@ -61,17 +65,23 @@ runs:
6165
echo "All inputs validated successfully."
6266
shell: bash
6367
- name: Push to GitLab
68+
env:
69+
GITLAB_URL: ${{ inputs.gitlab_url }}
70+
USERNAME: ${{ inputs.username }}
71+
GITLAB_PAT: ${{ inputs.gitlab_pat }}
72+
FORCE_PUSH: ${{ inputs.force_push }}
73+
GIT_LFS: ${{ inputs.git_lfs }}
6474
run: |
65-
gitlab_repo_url=${{ inputs.gitlab_url }}
66-
gitlab_repo_url=${gitlab_repo_url#https://}
67-
gitlab_repo_url_with_credentials="https://${{ inputs.username }}:${{ inputs.gitlab_pat }}@${gitlab_repo_url}"
75+
gitlab_repo_url="${GITLAB_URL#https://}"
76+
gitlab_repo_url_with_credentials="https://${USERNAME}:${GITLAB_PAT}@${gitlab_repo_url}"
77+
echo "::add-mask::$gitlab_repo_url_with_credentials"
6878
git remote add gitlab "$gitlab_repo_url_with_credentials"
69-
branch_name=$(echo $GITHUB_REF | sed 's/refs\/heads\///')
70-
if [[ "${{ inputs.git_lfs }}" == "true" ]]; then
79+
branch_name=$(echo "$GITHUB_REF" | sed 's/refs\/heads\///')
80+
if [[ "$GIT_LFS" == "true" ]]; then
7181
git lfs push --all gitlab
7282
fi
7383
push_command="git push gitlab $branch_name"
74-
if [[ "${{ inputs.force_push }}" == "true" ]]; then
84+
if [[ "$FORCE_PUSH" == "true" ]]; then
7585
push_command="$push_command --force"
7686
fi
7787
$push_command

0 commit comments

Comments
 (0)