Skip to content

fix: shell-escape dynamic values in pagination hint#210

Draft
bukinoshita wants to merge 2 commits intomainfrom
fix/escape-pagination-profile-f3b5
Draft

fix: shell-escape dynamic values in pagination hint#210
bukinoshita wants to merge 2 commits intomainfrom
fix/escape-pagination-profile-f3b5

Conversation

@bukinoshita
Copy link
Copy Markdown
Member

@bukinoshita bukinoshita commented Apr 9, 2026

Summary by cubic

Escapes dynamic values in the pagination hint using POSIX single-quote rules to prevent shell injection in copy-pasteable commands. Resolves BU-633 by safely quoting cursor, masked API key, and profile values.

  • Bug Fixes
    • Added shQuote utility for POSIX single-quote escaping.
    • Applied quoting in printPaginationHint for cursor, --api-key, and --profile.
    • Updated tests to cover metacharacters and embedded quotes.

Written for commit 72af19d. Summary will update on new commits.

printPaginationHint() was interpolating --profile, --api-key, and cursor
values directly into a copy-pasteable shell command without escaping.
A malicious --profile value containing shell metacharacters would be
reflected verbatim, allowing injection if the user copy-pasted the hint.

Add shQuote() (POSIX single-quote escaping) and apply it to all dynamic
arguments rendered in the pagination hint command.

Resolves BU-633

Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
@bukinoshita
Copy link
Copy Markdown
Member Author

@cubic-dev-ai can you review?

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai bot commented Apr 9, 2026

@cubic-dev-ai can you review?

@bukinoshita I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/lib/pagination.ts">

<violation number="1" location="src/lib/pagination.ts:59">
P2: Use `!== undefined` for Commander option presence instead of truthiness so explicitly provided empty-string values are not dropped from the generated hint.

(Based on your team's feedback about checking Commander option presence with `!== undefined`.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread src/lib/pagination.ts
const limitFlag = opts.limit ? ` --limit ${opts.limit}` : '';
const apiKeyFlag = opts.apiKey ? ` --api-key ${maskKey(opts.apiKey)}` : '';
const profileFlag = opts.profile ? ` --profile ${opts.profile}` : '';
const apiKeyFlag = opts.apiKey
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 9, 2026

Choose a reason for hiding this comment

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

P2: Use !== undefined for Commander option presence instead of truthiness so explicitly provided empty-string values are not dropped from the generated hint.

(Based on your team's feedback about checking Commander option presence with !== undefined.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/lib/pagination.ts, line 59:

<comment>Use `!== undefined` for Commander option presence instead of truthiness so explicitly provided empty-string values are not dropped from the generated hint.

(Based on your team's feedback about checking Commander option presence with `!== undefined`.) </comment>

<file context>
@@ -55,10 +56,12 @@ export function printPaginationHint(
   const limitFlag = opts.limit ? ` --limit ${opts.limit}` : '';
-  const apiKeyFlag = opts.apiKey ? ` --api-key ${maskKey(opts.apiKey)}` : '';
-  const profileFlag = opts.profile ? ` --profile ${opts.profile}` : '';
+  const apiKeyFlag = opts.apiKey
+    ? ` --api-key ${shQuote(maskKey(opts.apiKey))}`
+    : '';
</file context>
Fix with Cubic

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.

2 participants