CVE-2023-31128: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (CWE-78)
value: NextCloud Cookbook is a recipe library app. Prior to commit a46d9855 on the `master` branch and commit 489bb744 on the `main-0.9.x` branch, the `pull-checks.yml` workflow is vulnerable to command injection attacks because of using an untrusted `github.head_ref` field. The `github.head_ref` value is an attacker-controlled value. Assigning the value to `zzz";echo${IFS}"hello";#` can lead to command injection. Since the permission is not restricted, the attacker has a write-access to the repository. This issue is fixed in commit a46d9855 on the `master` branch and commit 489bb744 on the `main-0.9.x` branch. There is no risk for the user of the app within the NextCloud server. This only affects the main repository and possible forks of it. Those who have forked the NextCloud Cookbook repository should make sure their forks are on the latest version to prevent code injection attacks and similar.
CWE description: The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.
CVSS v3 base score: 8.8
Published: 2023-05-26T22:15Z
Repository: https://github.com/nextcloud/cookbook
Language: YAML
Files changed: .github/workflows/pull-checks.yml
Commit date: 2023-05-16 16:12:45 +0200
Commit message: Fix typo in workflow file

Signed-off-by: Christian Wolf <github@christianwolf.email>

Diff: diff --git a/.github/workflows/pull-checks.yml b/.github/workflows/pull-checks.yml
index bc110ed1..9692d306 100644
--- a/.github/workflows/pull-checks.yml
+++ b/.github/workflows/pull-checks.yml
@@ -58,15 +58,18 @@ jobs:
                     REPO="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
                     BRANCH="${GITHUB_REF/#refs\/heads\//}"
 
                     git clone --filter=tree:0 "$REPO" .
             -   name: Manual checkout of the app (PR head)
+                env:
+                    URL: ${{ github.event.pull_request.head.repo.html_url }}
+                    HEAD_REF: ${{ github.head_ref }}
                 run: |
-                    git remote add head "${{ github.event.pull_request.head.repo.html_url }}"
+                    git remote add head "$URL"
                     git fetch head --filter=tree:0
                     
-                    git checkout -b head-branch head/${{ github.head_ref }}
+                    git checkout -b head-branch head/$HEAD_REF
             -   name: Status of current git workspace
                 run: |
                     git branch
                     git status
             -   name: Check for open TODO annotations in source code

Vulnerable code:                     git remote add head "${{ github.event.pull_request.head.repo.html_url }}"
                    git checkout -b head-branch head/${{ github.head_ref }}
Fixed code:                 env:
                    URL: ${{ github.event.pull_request.head.repo.html_url }}
                    HEAD_REF: ${{ github.head_ref }}
                    git remote add head "$URL"
                    git checkout -b head-branch head/$HEAD_REF