Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/pr-automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Run Command on Comment

on:
issue_comment:
types:
- created

jobs:
process_comment:
runs-on: ubuntu-latest
steps:
- name: Check if the comment contains the run command
id: check_comment
run: |
commands=echo '${{ github.event.comment.body }}' | grep -oPz '```run_this\n(just .*\n)*```\n' |

Check failure

Code scanning / CodeQL

Code injection Critical

Potential code injection in
${ github.event.comment.body }
, which may be controlled by an external user (
issue_comment
).

Copilot Autofix

AI 24 days ago

How to fix:
Replace the direct interpolation of ${{ github.event.comment.body }} into the shell command with safe usage via environment variables.

Detailed fix:
At the start of the step where we use ${{ github.event.comment.body }}, add an env: block to assign its value to an environment variable, e.g., COMMENT_BODY. Then, in the run: command, reference the value with proper shell variable syntax ("$COMMENT_BODY"). This allows the shell to safely parse the value regardless of its content and prevents opportunity for code injection or unintended expansion.

Concrete changes:

  • On step 13-15, add an env: field to assign COMMENT_BODY: ${{ github.event.comment.body }}.
  • In the script on line 15, replace echo '${{ github.event.comment.body }}' with echo "$COMMENT_BODY".
  • No new imports or actions are needed.

Suggested changeset 1
.github/workflows/pr-automation.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/pr-automation.yml b/.github/workflows/pr-automation.yml
--- a/.github/workflows/pr-automation.yml
+++ b/.github/workflows/pr-automation.yml
@@ -11,8 +11,10 @@
     steps:
       - name: Check if the comment contains the run command
         id: check_comment
+        env:
+          COMMENT_BODY: ${{ github.event.comment.body }}
         run: |
-          commands=echo '${{ github.event.comment.body }}' | grep -oPz '```run_this\n(just .*\n)*```\n' | 
+          commands=$(echo "$COMMENT_BODY" | grep -oPz '```run_this\n(just .*\n)*```\n')
       - uses: actions/checkout@v3
         if: steps.check_comment.outputs.commands != ''
       - name: Install toolchain
EOF
@@ -11,8 +11,10 @@
steps:
- name: Check if the comment contains the run command
id: check_comment
env:
COMMENT_BODY: ${{ github.event.comment.body }}
run: |
commands=echo '${{ github.event.comment.body }}' | grep -oPz '```run_this\n(just .*\n)*```\n' |
commands=$(echo "$COMMENT_BODY" | grep -oPz '```run_this\n(just .*\n)*```\n')
- uses: actions/checkout@v3
if: steps.check_comment.outputs.commands != ''
- name: Install toolchain
Copilot is powered by AI and may make mistakes. Always verify output.
- uses: actions/checkout@v3
if: steps.check_comment.outputs.commands != ''
- name: Install toolchain
if: steps.check_comment.outputs.commands != ''
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- uses: Swatinem/rust-cache@v2
if: steps.check_comment.outputs.commands != ''
with:
cache-provider: "warpbuild"
- name: Install just
if: steps.check_comment.outputs.commands != ''
run: cargo install just
- name: Execute the commands
if: steps.check_comment.outputs.commands != ''
id: execute_commands
run: |
echo "${{ steps.check_comment.outputs.commands }}" | while read line; do
echo "[$line]"
if [ "$line" = "\`\`\`run_this" ]; then
OUTPUT=""
elif [[ "$line" = "\`\`\`" ]]; then
echo "Results:"
echo "\`\`\`"
echo "$OUTPUT"
echo "\`\`\`"
else
NEWOUTPUT=$(bash -c "$line" 2>&1)
OUTPUT="$OUTPUT $NEWOUTPUT"
fi
done
- name: Create commit comment
if: steps.check_comment.outputs.commands != ''
uses: peter-evans/commit-comment@v4
with:
body: |
Running:
${{ steps.check_comment.outputs.commands }}

Results:
```
${{ steps.execute_commands.outputs.OUTPUT }}
```
Comment on lines +10 to +59

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 24 days ago

The best way to fix this issue is to explicitly set a permissions block within the workflow (either globally or just for this job) that grants only the required privileges. For this workflow, the main requirements are:

  • Read access to repository contents for checkout.
  • Ability to write commit comments (for peter-evans/commit-comment@v4 action), which requires contents: write (since commit comments are part of code, not issue comments).
  • All other scopes should remain unset for least privilege.

The most conservative recommendation is to add the following block at the same level as jobs:, above jobs::

permissions:
  contents: write

Alternatively, if you wish to restrict permissions further and only give write at the job level (not globally), you can add the permissions: block under jobs.process_comment:, but the global fix is typical.

Action: Insert the following block between line 2 and line 3 in the .github/workflows/pr-automation.yml file:

permissions:
  contents: write

No additional imports or definitions are required for YAML workflows.

Suggested changeset 1
.github/workflows/pr-automation.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/pr-automation.yml b/.github/workflows/pr-automation.yml
--- a/.github/workflows/pr-automation.yml
+++ b/.github/workflows/pr-automation.yml
@@ -1,5 +1,7 @@
 name: Run Command on Comment
 
+permissions:
+  contents: write
 on:
   issue_comment:
     types:
EOF
@@ -1,5 +1,7 @@
name: Run Command on Comment

permissions:
contents: write
on:
issue_comment:
types:
Copilot is powered by AI and may make mistakes. Always verify output.
Loading