Skip to content

fix(code-placeholders): harden shell placeholder interpolation in arithmetic contexts - #8760

Open
waleedlatif1 wants to merge 1 commit into
stagingfrom
fix/code-placeholders-arithmetic-contexts
Open

waleedlatif1 wants to merge 1 commit into
stagingfrom
fix/code-placeholders-arithmetic-contexts

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Shell placeholders are now rejected in every position where bash evaluates the substituted value as arithmetic. Before, only $(( )), $[ ] and (( )) were covered.
  • Heredocs opened inside an arithmetic context, whether quoted or unquoted, now inherit that context. The heredoc operator is scanned with the rest of the script, so its position decides whether its body feeds arithmetic.
  • New arithmetic contexts:
    • operands of -eq/-ne/-lt/-le/-gt/-ge inside [[ ]]
    • let arguments
    • declare/typeset/local -i assignments, and later assignments to names declared integer
    • indexed-array subscripts (${a[...]}, a[...]=, ([...]=), and quoted name[...] passed to builtins that take a variable name)
    • ${name:offset:length}
  • The [ ] / test builtin, default-value expansions (${x:-...}) and plain heredocs outside arithmetic still compile as before. Detection is conservative where a position cannot be decided precisely.
  • The scanner's command marking stays linear on deeply nested or repetitive input.

Type of Change

  • Bug fix

Testing

  • Extended the rejects shell placeholders whose values enter arithmetic table with 30 cases. All of them fail on the previous scanner.
  • Added a bash-executed test showing that placeholders beside arithmetic, but never evaluated by it, still compile and run unchanged.
  • bunx vitest run lib/execution/ (52 files, 1177 tests), root bun run test, bun run lint, bun run type-check, bun run check:audits (58 audits).

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 8, 2026 12:51am UTC

Request Review

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 1/5

[Medium risk] Hardens shell placeholder interpolation in arithmetic contexts.

The PR should not merge until both attribute-tracking gaps stop supplied values from running embedded commands.

Findings

  1. P1 Security Array declarations lose protection ▶
  2. P1 Security Function removal loses protection ▶

Summary

The PR adds arithmetic checks for shell comparisons, declarations, array indexes, substring offsets, and heredocs whose output feeds arithmetic.

  • Two attribute-tracking gaps still let supplied values run embedded commands.
  • Added tests cover arithmetic rejection and nearby ordinary text.
  • All supplied previous threads are unnumbered, so none require a numbered entry in previousFindings.
  • In an earlier reply, waleedlatif1 accepted deferring cross-statement integer tracking because precise tracking needed fuller name tracking. The current code now tracks those attributes.

Reviews (11) · Last reviewed commit: "fix(code-placeholders): harden shell pla..." · Reviewed by Greptile

Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from 9dfab5f to 1a74dc6 Compare October 7, 2026 20:40
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

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

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 3 files

Confidence score: 3/5

  • shell.ts misses arithmetic commands invoked through command or builtin, so builtin let n={{KEY}} can bypass arithmetic detection. Extend detection to recognize these prefixes.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/execution/code-placeholders/shell.ts">

<violation number="1" location="apps/sim/lib/execution/code-placeholders/shell.ts:659">
P2: `command` and `builtin` can prefix Bash builtins, but this treats the prefix as the command and ignores the following `let`; `builtin let n={{KEY}}` bypasses arithmetic detection. Recognize these invocation prefixes before selecting the command word.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from 1a74dc6 to f0150b8 Compare October 7, 2026 21:09
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

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

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from f0150b8 to fbc91c8 Compare October 7, 2026 21:34
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from fbc91c8 to 6d07b57 Compare October 7, 2026 21:37
@cubic-dev-ai

cubic-dev-ai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

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

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from 6d07b57 to 0477e23 Compare October 7, 2026 22:04

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from 1f8cc67 to 77eef69 Compare October 7, 2026 23:48
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from 77eef69 to d50f692 Compare October 8, 2026 00:01
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

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

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from d50f692 to 91315e4 Compare October 8, 2026 00:20
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from 91315e4 to a3c63ce Compare October 8, 2026 00:29
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

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

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 3 files

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
Comment thread apps/sim/lib/execution/code-placeholders/shell.ts Outdated
@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from a3c63ce to 807488d Compare October 8, 2026 00:45
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
waleedlatif1 force-pushed the fix/code-placeholders-arithmetic-contexts branch from 807488d to 2f3e963 Compare October 8, 2026 00:51
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

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

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.

Turn on auto-fix | Re-trigger cubic

if (declared) {
// A re-declaration resets the name's type before this one's attributes apply, so a later
// `declare -a` (indexed) clears an earlier `-A` (associative) and vice versa.
if (command.associativeOption || command.indexedOption) clearNameType(declared)

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.

P1 security Array declarations lose protection

declare -a and declare -A erase a previously tracked integer attribute, but Bash keeps it unless +i clears it. For example, declare -i n; declare -a n; n="{{KEY}}" compiles. With KEY=values[$(printf injected >&2)], Bash runs the embedded command. Preserve the integer attribute when updating the array type.

How this was verified: The compiled example ran in Bash and printed injected from the supplied assignment value.

Comment on lines +909 to +910
if (command.nameArgumentBuiltin && command.sawCommandWord && SHELL_BARE_NAME.test(word)) {
clearNameType(word)

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.

P1 security Function removal loses protection

unset -f removes functions, not variables, but this branch clears variable attributes for its name arguments. declare -i n; unset -f n; n="{{KEY}}" therefore compiles even though Bash keeps n integer. With KEY=values[$(printf injected >&2)], the assignment runs the embedded command. Track the unset options and clear variable attributes only when the command removes a variable.

How this was verified: The compiled example ran in Bash and printed injected while unset -f left the integer variable unchanged.

This branch was previously deployed

1 inactive deployment
Preview — 2f3e963b Deployed Oct 8, 2026 by vercel[bot]
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.

1 participant