Skip to content

fix: resolve open CodeQL alerts (shell command construction, table-cell escaping, workflow permissions) - #1026

Merged
wmadden merged 3 commits into
mainfrom
codeql/fix-open-alerts
Jul 22, 2026
Merged

fix: resolve open CodeQL alerts (shell command construction, table-cell escaping, workflow permissions)#1026
wmadden merged 3 commits into
mainfrom
codeql/fix-open-alerts

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Resolves the six pre-existing open CodeQL alerts on main. Every alert was a genuine finding; none is dismissed as a false positive.

Shell command construction in record.ts (alerts #10, #11, #12js/shell-command-injection-from-environment)

The recording script built shell command strings by interpolating absolute paths (node ${CLI_BIN} …, vhs ${tapePath}). Per CodeQL's recommended remediation, all three sites now use execFileSync with argument arrays, so no shell parses the paths:

  • probeCliOutput splits the config-sourced command on whitespace — every command: entry in recordings/config.ts is plain space-separated tokens, so the split is faithful.
  • runCliIn already had an args array and now passes it through directly. This also fixes latent mangling of any future arg containing spaces (previously join(' ') then shell-split).
  • runVhs runs vhs with the tape path as a single argument.

The error path is unchanged: execFileSync failures carry the same stdout/stderr properties the catch block reads.

Backslash escaping in review-table renderers (alerts #36, #37js/incomplete-sanitization)

escapeTableCell in render-review-state.mjs and render-review-actions.mjs escaped | but not \, so input like foo \| bar (or a trailing backslash) produced \\| — a literal backslash followed by a live cell separator, corrupting the Markdown table. Backslashes are now escaped before pipes.

Tests came first: new node:test files next to each script drive the exported render functions with backslash+pipe payloads and assert the exact escaped rows. Both failed against the old code and are wired into the root test:scripts, so they run in CI.

Explicit workflow permissions (alert #1actions/missing-workflow-permissions)

The secret-detection job in pr-code-security.yml called the reusable prisma/.github secret-detection workflow with no permissions block, defaulting to the repo's full token. It now grants exactly what the reusable workflow's job declares (contents: read, pull-requests: write); the code-scanning job already had its own block, so every job now carries explicit permissions.

Alerts #24/#25 (op-factory-call.ts) were already fixed by #1018 and are not touched here.

Verification

Full local run on this branch: build, typecheck, the lint suite (incl. lint:workflows, lint:skills), test:packages, test:scripts (222 pass, incl. the two new files), and fixtures:check — all green.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved Markdown table rendering in review outputs so backslashes and pipes display correctly.
    • Improved “Source:” and file path formatting to preserve literal backslashes and safely escape pipes/backticks in inline code.
    • Improved CLI command execution to handle argument passing more reliably for probing/recording.
  • Tests
    • Added/expanded coverage for Markdown escaping and inline code edge cases in review state and review actions.
    • Updated script test execution to use the correct synchronization test file.
  • Chores
    • Updated automated workflow permissions to enable secret detection with pull-request comments.

…ll escaping, workflow permissions)

- record.ts: replace execSync template strings with execFileSync argument
  arrays (js/shell-command-injection-from-environment, alerts 10-12)
- review renderers: escape backslashes before pipes in escapeTableCell,
  with tests wired into test:scripts (js/incomplete-sanitization, 36-37)
- pr-code-security.yml: explicit permissions on the secret-detection job
  (actions/missing-workflow-permissions, alert 1)

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner July 22, 2026 12:57
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 260f1da4-1433-471a-acd0-6d87c4e7f5b8

📥 Commits

Reviewing files that changed from the base of the PR and between c11fa7d and aba1ce7.

📒 Files selected for processing (4)
  • skills-contrib/review-fetch-phase/scripts/render-review-state.mjs
  • skills-contrib/review-fetch-phase/scripts/render-review-state.test.mjs
  • skills-contrib/review-triage-phase/scripts/render-review-actions.mjs
  • skills-contrib/review-triage-phase/scripts/render-review-actions.test.mjs
🚧 Files skipped from review as they are similar to previous changes (2)
  • skills-contrib/review-triage-phase/scripts/render-review-actions.mjs
  • skills-contrib/review-fetch-phase/scripts/render-review-state.mjs

📝 Walkthrough

Walkthrough

The PR adds secret-detection permissions, updates the script test target, switches CLI subprocesses to argument arrays, and improves Markdown escaping and code-span formatting in two renderers with tests.

Changes

Markdown table escaping

Layer / File(s) Summary
Renderer escaping and coverage
skills-contrib/review-fetch-phase/scripts/*, skills-contrib/review-triage-phase/scripts/*
Both renderers now escape backslashes in table cells, format paths with collision-safe inline code spans, and test values containing pipes, backslashes, and backticks.

CLI process execution

Layer / File(s) Summary
Argument-safe subprocess execution
packages/1-framework/3-tooling/cli/scripts/record.ts
CLI probing, CLI execution, and VHS invocation now pass executable arguments as arrays through execFileSync.

Workflow and test selection

Layer / File(s) Summary
Security permissions and script test target
.github/workflows/pr-code-security.yml, package.json
The secret-detection job declares contents-read and pull-request-write permissions, and test:scripts targets sync-agent-rules.test.mjs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main PR scope: fixing CodeQL alerts via shell command construction, table-cell escaping, and workflow permissions.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codeql/fix-open-alerts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 161.81 KB (-0.81% 🔽)
postgres / emit 145.14 KB (-0.11% 🔽)
mongo / no-emit 99.67 KB (-0.48% 🔽)
mongo / emit 89.86 KB (0%)
cf-worker / no-emit 186.83 KB (-0.84% 🔽)
cf-worker / emit 168.17 KB (-0.27% 🔽)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
skills-contrib/review-triage-phase/scripts/render-review-actions.test.mjs (1)

32-39: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover targetFiles code-span rendering.

The assertions cover table cells but not targetFiles, which passes through formatCodePaths(). Add a target file containing a literal backslash and assert that the rendered code span preserves one slash.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills-contrib/review-triage-phase/scripts/render-review-actions.test.mjs`
around lines 32 - 39, Add coverage in the “escapes backslashes before pipes in
table cells” test for targetFiles rendered through formatCodePaths(). Include a
target file containing a literal backslash in buildPayload() and assert the
rendered code span preserves exactly one backslash.
skills-contrib/review-fetch-phase/scripts/render-review-state.test.mjs (1)

39-48: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add coverage for escaped source paths outside table cells.

This test verifies a table row but not sourcePath inside the inline code span. Add a literal-backslash sourcePath assertion so the rendering regression is caught.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@skills-contrib/review-fetch-phase/scripts/render-review-state.test.mjs`
around lines 39 - 48, Add an assertion in the test “escapes backslashes before
pipes in table cells” that checks the rendered inline code span also preserves
and escapes literal backslashes in sourcePath, using the existing markdown
output and expected escaped path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/1-framework/3-tooling/cli/scripts/record.ts`:
- Around line 115-118: Update probeCliOutput to tokenize the command arguments
with shell-quoting support instead of splitting args on whitespace, while
continuing to invoke execFileSync without a shell. Preserve quoted values such
as "two words" as a single argv element and keep the existing command-prefix
removal behavior.

In `@skills-contrib/review-fetch-phase/scripts/render-review-state.mjs`:
- Line 78: Separate Markdown table-cell escaping from inline-code formatting:
update render-review-state.mjs at lines 78-78 to use a code-span-specific
formatter for sourcePath, and update render-review-actions.mjs at lines 87-87 to
use it for formatCodePaths() and sourcePath without escaping literal
backslashes. Add regression coverage for backslash-containing sourcePath in
render-review-state.test.mjs lines 39-48 and backslash-containing targetFiles in
render-review-actions.test.mjs lines 32-39, preserving the existing table
escaping behavior.

---

Nitpick comments:
In `@skills-contrib/review-fetch-phase/scripts/render-review-state.test.mjs`:
- Around line 39-48: Add an assertion in the test “escapes backslashes before
pipes in table cells” that checks the rendered inline code span also preserves
and escapes literal backslashes in sourcePath, using the existing markdown
output and expected escaped path.

In `@skills-contrib/review-triage-phase/scripts/render-review-actions.test.mjs`:
- Around line 32-39: Add coverage in the “escapes backslashes before pipes in
table cells” test for targetFiles rendered through formatCodePaths(). Include a
target file containing a literal backslash in buildPayload() and assert the
rendered code span preserves exactly one backslash.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 7ce604f0-7f46-44d5-b2da-30665bbdadbd

📥 Commits

Reviewing files that changed from the base of the PR and between 6285c8e and d1c0d31.

📒 Files selected for processing (7)
  • .github/workflows/pr-code-security.yml
  • package.json
  • packages/1-framework/3-tooling/cli/scripts/record.ts
  • skills-contrib/review-fetch-phase/scripts/render-review-state.mjs
  • skills-contrib/review-fetch-phase/scripts/render-review-state.test.mjs
  • skills-contrib/review-triage-phase/scripts/render-review-actions.mjs
  • skills-contrib/review-triage-phase/scripts/render-review-actions.test.mjs

Comment thread packages/1-framework/3-tooling/cli/scripts/record.ts
Comment thread skills-contrib/review-fetch-phase/scripts/render-review-state.mjs
@pkg-pr-new

pkg-pr-new Bot commented Jul 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@1026

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@1026

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@1026

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@1026

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@1026

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@1026

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@1026

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@1026

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@1026

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@1026

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@1026

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@1026

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@1026

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@1026

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@1026

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@1026

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@1026

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@1026

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@1026

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@1026

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@1026

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@1026

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@1026

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@1026

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@1026

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@1026

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@1026

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@1026

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@1026

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@1026

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@1026

@prisma-next/config-loader

npm i https://pkg.pr.new/@prisma-next/config-loader@1026

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@1026

@prisma-next/language-server

npm i https://pkg.pr.new/@prisma-next/language-server@1026

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@1026

prisma-next

npm i https://pkg.pr.new/prisma-next@1026

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@1026

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@1026

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@1026

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@1026

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@1026

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@1026

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@1026

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@1026

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@1026

@prisma-next/mongo-orm

npm i https://pkg.pr.new/@prisma-next/mongo-orm@1026

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@1026

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@1026

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@1026

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@1026

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@1026

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@1026

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@1026

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@1026

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@1026

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@1026

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@1026

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@1026

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@1026

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@1026

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@1026

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@1026

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@1026

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@1026

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@1026

commit: aba1ce7

Backslashes are literal inside Markdown code spans, so routing code-span
content through escapeTableCell doubled them. Add formatCodeSpan (escapes
pipes for GFM table cells, leaves backslashes intact) and use it for the
Source line in both renderers and for formatCodePaths.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@wmadden-electric

Copy link
Copy Markdown
Contributor Author

Done in c11fa7d (both nitpicks from the review body): render-review-state.test.mjs now asserts a literal-backslash sourcePath renders unchanged in the Source code span, and render-review-actions.test.mjs covers formatCodePaths() with a backslash-containing target file. Backing fix: formatCodeSpan escapes pipes but leaves backslashes literal.

Comment thread skills-contrib/review-fetch-phase/scripts/render-review-state.mjs Dismissed
Comment thread skills-contrib/review-triage-phase/scripts/render-review-actions.mjs Dismissed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@skills-contrib/review-triage-phase/scripts/render-review-actions.mjs`:
- Around line 93-104: Update formatCodeSpan() to choose a Markdown code fence
longer than the longest consecutive backtick run in the normalized text,
ensuring backtick-containing values cannot terminate the span; preserve existing
whitespace and pipe normalization. Add a regression test covering
backtick-containing paths passed through formatCodePaths().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: d33a529e-940f-4a55-878d-0435898f8b22

📥 Commits

Reviewing files that changed from the base of the PR and between d1c0d31 and c11fa7d.

📒 Files selected for processing (4)
  • skills-contrib/review-fetch-phase/scripts/render-review-state.mjs
  • skills-contrib/review-fetch-phase/scripts/render-review-state.test.mjs
  • skills-contrib/review-triage-phase/scripts/render-review-actions.mjs
  • skills-contrib/review-triage-phase/scripts/render-review-actions.test.mjs
🚧 Files skipped from review as they are similar to previous changes (3)
  • skills-contrib/review-fetch-phase/scripts/render-review-state.test.mjs
  • skills-contrib/review-triage-phase/scripts/render-review-actions.test.mjs
  • skills-contrib/review-fetch-phase/scripts/render-review-state.mjs

Wrap code spans with a backtick fence longer than the longest backtick
run in the content, space-padded when the content starts or ends with a
backtick, so backtick-containing paths render as intact code spans.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@wmadden
wmadden added this pull request to the merge queue Jul 22, 2026
Merged via the queue into main with commit e1b778d Jul 22, 2026
22 checks passed
@wmadden
wmadden deleted the codeql/fix-open-alerts branch July 22, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants