CVE-2024-39700: Insufficient Information (NVD-CWE-noinfo)
value: JupyterLab extension template is a  `copier` template for JupyterLab extensions. Repositories created using this template with `test` option include `update-integration-tests.yml` workflow which has an RCE vulnerability. Extension authors hosting their code on GitHub are urged to upgrade the template to the latest version. Users who made changes to `update-integration-tests.yml`, accept overwriting of this file and re-apply your changes later. Users may wish to temporarily disable GitHub Actions while working on the upgrade. We recommend rebasing all open pull requests from untrusted users as actions may run using the version from the `main` branch at the time when the pull request was created. Users who are upgrading from template version prior to 4.3.0 may wish to leave out proposed changes to the release workflow for now as it requires additional configuration.
CWE description: There is insufficient information about the issue to classify it; details are unkown or unspecified.
Published: 2024-07-16T18:15Z
Repository: https://github.com/jupyterlab/extension-template
Language: Other
Files changed: template/.github/workflows/{% if test %}update-integration-tests.yml{% endif %}	
Commit date: 2024-07-09 14:07:27 +0100
Commit message: Merge pull request from GHSA-45gq-v5wm-82wg

* Fix for update-snapshots template

Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com>
Co-authored-by: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com>

* Update date check

* Pull in changes from hotfix 16560

---------

Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com>
Co-authored-by: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com>
Diff: diff --git a/template/.github/workflows/{% if test %}update-integration-tests.yml{% endif %} b/template/.github/workflows/{% if test %}update-integration-tests.yml{% endif %}
index 8548dc3..1cae0ed 100644
--- a/template/.github/workflows/{% if test %}update-integration-tests.yml{% endif %}	
+++ b/template/.github/workflows/{% if test %}update-integration-tests.yml{% endif %}	
@@ -8,11 +8,16 @@ permissions:
   contents: write
   pull-requests: write
 
 jobs:
   update-snapshots:
-    if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, 'please update snapshots') }}
+    if: >
+      (
+        github.event.issue.author_association == 'OWNER' ||
+        github.event.issue.author_association == 'COLLABORATOR' ||
+        github.event.issue.author_association == 'MEMBER'
+      ) && github.event.issue.pull_request && contains(github.event.comment.body, 'please update snapshots')
     runs-on: ubuntu-latest
 
     steps:
       - name: React to the triggering comment
         run: |
@@ -23,14 +28,44 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v4
         with:
           token: ${{ secrets.GITHUB_TOKEN }}
 
+      - name: Get PR Info
+        id: pr
+        env:
+          PR_NUMBER: ${{ github.event.issue.number }}
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+          GH_REPO: ${{ github.repository }}
+          COMMENT_AT: ${{ github.event.comment.created_at }}
+        run: |
+          pr="$(gh api /repos/${GH_REPO}/pulls/${PR_NUMBER})"
+          head_sha="$(echo "$pr" | jq -r .head.sha)"
+          pushed_at="$(echo "$pr" | jq -r .pushed_at)"
+
+          if [[ $(date -d "$pushed_at" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then
+              echo "Updating is not allowed because the PR was pushed to (at $pushed_at) after the triggering comment was issued (at $COMMENT_AT)"
+              exit 1
+          fi
+
+          echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
+
       - name: Checkout the branch from the PR that triggered the job
-        run: gh pr checkout ${{ github.event.issue.number }}
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: gh pr checkout ${{ github.event.issue.number }}
+
+      - name: Validate the fetched branch HEAD revision
+        env:
+          EXPECTED_SHA: ${{ steps.pr.outputs.head_sha }}
+        run: |
+          actual_sha="$(git rev-parse HEAD)"
+
+          if [[ "$actual_sha" != "$EXPECTED_SHA" ]]; then
+              echo "The HEAD of the checked out branch ($actual_sha) differs from the HEAD commit available at the time when trigger comment was submitted ($EXPECTED_SHA)"
+              exit 1
+          fi
 
       - name: Base Setup
         uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
 
       - name: Install dependencies

Vulnerable code:     if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, 'please update snapshots') }}
        run: gh pr checkout ${{ github.event.issue.number }}
Fixed code:     if: >
      (
        github.event.issue.author_association == 'OWNER' ||
        github.event.issue.author_association == 'COLLABORATOR' ||
        github.event.issue.author_association == 'MEMBER'
      ) && github.event.issue.pull_request && contains(github.event.comment.body, 'please update snapshots')
      - name: Get PR Info
        id: pr
        env:
          PR_NUMBER: ${{ github.event.issue.number }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GH_REPO: ${{ github.repository }}
          COMMENT_AT: ${{ github.event.comment.created_at }}
        run: |
          pr="$(gh api /repos/${GH_REPO}/pulls/${PR_NUMBER})"
          head_sha="$(echo "$pr" | jq -r .head.sha)"
          pushed_at="$(echo "$pr" | jq -r .pushed_at)"

          if [[ $(date -d "$pushed_at" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then
              echo "Updating is not allowed because the PR was pushed to (at $pushed_at) after the triggering comment was issued (at $COMMENT_AT)"
              exit 1
          fi

          echo "head_sha=$head_sha" >> $GITHUB_OUTPUT

        run: gh pr checkout ${{ github.event.issue.number }}

      - name: Validate the fetched branch HEAD revision
        env:
          EXPECTED_SHA: ${{ steps.pr.outputs.head_sha }}
        run: |
          actual_sha="$(git rev-parse HEAD)"

          if [[ "$actual_sha" != "$EXPECTED_SHA" ]]; then
              echo "The HEAD of the checked out branch ($actual_sha) differs from the HEAD commit available at the time when trigger comment was submitted ($EXPECTED_SHA)"
              exit 1
          fi