From 2031c12ff4a458d691f0d0feeeb81c939f0bdba5 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 17 Aug 2026 12:09:48 -0700 Subject: [PATCH] Fix CodeQL alerts: workflow permissions and shell injection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Alert #1 (actions/missing-workflow-permissions, .github/workflows/main.yml:12) — the single `build` job only checks out the repo, sets up Ruby, and runs `bundle exec rake` (rspec + rubocop). No writes of any kind, so a workflow-level `contents: read` is the correct least privilege. Placed at the workflow level after `on:`, which matches the existing style in this repo's release.yml. Alert #2 (rb/shell-command-constructed-from-input, lib/chatwerk/cli.rb:20) — the `inspect` Thor command interpolated the user-supplied working directory into a single string passed to `system`, so Ruby handed it to /bin/sh. Passing separate argv entries bypasses the shell entirely; the `PWD=#{pwd}` interpolation is now a single argv element and can no longer break out of its argument. No spec stubs or asserts on this call, and the observable command is unchanged. --- .github/workflows/main.yml | 3 +++ lib/chatwerk/cli.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e5ade69..f76a6e0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,6 +7,9 @@ on: pull_request: +permissions: + contents: read + jobs: build: runs-on: ubuntu-latest diff --git a/lib/chatwerk/cli.rb b/lib/chatwerk/cli.rb index e1aaa1a..28e19ae 100644 --- a/lib/chatwerk/cli.rb +++ b/lib/chatwerk/cli.rb @@ -17,7 +17,7 @@ def mcp desc 'inspect [WORKING_DIRECTORY]', 'Run the MCP inspector with an optional working directory path (defaults to current directory)' def inspect(working_directory = nil) pwd = working_directory || Dir.pwd - system("npx @modelcontextprotocol/inspector -e PWD=#{pwd} bundle exec exe/chatwerk mcp") + system('npx', '@modelcontextprotocol/inspector', '-e', "PWD=#{pwd}", 'bundle', 'exec', 'exe/chatwerk', 'mcp') end desc 'print_env', 'Show current environment details'