Skip to content

Block auto-approve for sed scripts that run commands or write files - #329216

Merged
anthonykim1 merged 4 commits into
mainfrom
anthonykim1/sed-positional-script-auto-approve
Aug 5, 2026
Merged

Block auto-approve for sed scripts that run commands or write files#329216
anthonykim1 merged 4 commits into
mainfrom
anthonykim1/sed-positional-script-auto-approve

Conversation

@anthonykim1

@anthonykim1 anthonykim1 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Part of: #329218

  • Extend the default sed deny rules to cover standalone e, r, R, w, and W commands supplied as positional scripts.
  • Match commands at the start of a script, after ;, or inside { ... }, including line, $, /regex/, and repeated // addresses.
  • Keep quoted-script matching delimiter-aware and escape-aware, and allow the whitespace, ! negation, and end-of-command boundaries accepted by sed.
  • Skip leading flags and operands consumed by -l/--line-length so the positional script is still inspected.
  • Apply the same policy to the workbench defaults and the Agent Host fallback defaults.
  • Preserve auto-approval for ordinary forms such as sed 's/foo/bar/g' file.txt, sed -n '1,10p' file.txt, and sed '/w/d' file.txt.

The patterns intentionally fail safe: a literal ;e or {e inside a replacement string asks for confirmation instead of auto-approving. A shared script analyzer can remove that conservative match and cover additional sed grammar without duplicating more regex logic; that follow-up is tracked in #329218.


Inspirations from:

The sed deny rules only matched flag-based forms (-e/-f/--expression/--file)
and s/// flags, so positional script arguments fell through to the allow rule.
Extend the deny patterns to cover standalone script commands and mirror the
change in the agent host fallback defaults.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 102bf1fe-34f3-4b81-b22f-5677ace2be4d
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 102bf1fe-34f3-4b81-b22f-5677ace2be4d

Copilot AI 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.

Pull request overview

Tightens default sed auto-approval rules across workbench and Agent Host.

Changes:

  • Adds deny patterns for dangerous positional sed scripts.
  • Mirrors rules across both approval implementations.
  • Adds regression tests for blocked forms.
Show a summary per file
File Description
commandLineAutoApprover.test.ts Tests workbench defaults.
terminalChatAgentToolsConfiguration.ts Extends workbench deny rules.
commandAutoApprover.test.ts Tests Agent Host defaults.
commandAutoApprover.ts Mirrors Agent Host deny rules.

Review details

Suppressed comments (2)

src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalChatAgentToolsConfiguration.ts:321

  • The unquoted rule omits the /regex/ address grammar supported by the quoted rules. sed /pat/e input.txt is a valid shell invocation, and GNU sed's argumentless e executes matching pattern-space contents; this line does not match it, so the generic sed allow rule approves it. Include regex addresses in the unquoted grammar and add a regression case.
			// Unquoted positional script form (e.g. `sed 1e id`, `sed w file`)
			'/^sed\\b(?:\\s+-\\S+)*\\s+(?:(?:\\d+|\\$)(?:,(?:\\d+|\\$))?)?[erRwW]\\s/': false,

src/vs/platform/agentHost/node/commandAutoApprover.ts:651

  • The mirrored unquoted rule omits /regex/ addresses. sed /pat/e input.txt is valid, and GNU sed's argumentless e executes matching pattern-space contents; because this does not match any deny rule, it is approved by sed: true. Include the regex-address grammar here and cover it in the Agent Host test.
	// Unquoted positional script form (e.g. `sed 1e id`, `sed w file`)
	'/^sed\\b(?:\\s+-\\S+)*\\s+(?:(?:\\d+|\\$)(?:,(?:\\d+|\\$))?)?[erRwW]\\s/': false,
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread src/vs/platform/agentHost/node/commandAutoApprover.ts Outdated
@anthonykim1
anthonykim1 marked this pull request as draft August 5, 2026 17:28
Capture the opening quote so the closing quote must match it, allow the
insignificant whitespace and `!` that sed permits around an address, and accept
regex addresses in the unquoted script form.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 102bf1fe-34f3-4b81-b22f-5677ace2be4d
@anthonykim1 anthonykim1 changed the title Tighten sed argument handling in terminal auto-approve defaults Block auto-approve for sed scripts that run commands or write files Aug 5, 2026
@anthonykim1
anthonykim1 requested a balanced review from Copilot August 5, 2026 17:40
@anthonykim1 anthonykim1 self-assigned this Aug 5, 2026
@anthonykim1 anthonykim1 added this to the 1.133.0 milestone Aug 5, 2026
@anthonykim1
anthonykim1 marked this pull request as ready for review August 5, 2026 17:41

Copilot AI 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.

Review details

Suppressed comments (4)

src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalChatAgentToolsConfiguration.ts:323

  • This quote/address scan still has valid bypasses. sed "s/a/\\\"/;e id" file stops scanning at the escaped ", and sed '/x/p;//e id' file uses sed's valid empty // address, which this +-based address branch rejects; both then fall through to sed: true. Consume escaped characters before checking the closing delimiter, permit the empty-regex address where a prior expression can establish it, and add both regressions.
			'/^sed\\b(?:\\s+-\\S+)*\\s+([\'"])(?:(?!\\1).)*[;{]\\s*(?:(?:\\d+|\\$|\\/(?:\\\\.|[^\\/])+\\/)(?:\\s*,\\s*(?:\\d+|\\$|\\/(?:\\\\.|[^\\/])+\\/))?)?\\s*!?\\s*[erRwW](?:\\s|\\1|[;}])/': false,

src/vs/platform/agentHost/node/commandAutoApprover.ts:651

  • This quote/address scan still has valid bypasses. sed "s/a/\\\"/;e id" file stops scanning at the escaped ", and sed '/x/p;//e id' file uses sed's valid empty // address, which this +-based address branch rejects; both then fall through to sed: true. Consume escaped characters before checking the closing delimiter, permit the empty-regex address where a prior expression can establish it, and add both regressions.
	'/^sed\\b(?:\\s+-\\S+)*\\s+([\'"])(?:(?!\\1).)*[;{]\\s*(?:(?:\\d+|\\$|\\/(?:\\\\.|[^\\/])+\\/)(?:\\s*,\\s*(?:\\d+|\\$|\\/(?:\\\\.|[^\\/])+\\/))?)?\\s*!?\\s*[erRwW](?:\\s|\\1|[;}])/': false,

src/vs/workbench/contrib/terminalContrib/chatAgentTools/common/terminalChatAgentToolsConfiguration.ts:325

  • This still auto-approves the valid GNU sed script sed e (and therefore a pipeline such as printf 'id\n' | sed e). With no command argument, e executes the current pattern space, but the unquoted matcher requires trailing whitespace, so the subcommand falls through to sed: true. Treat end-of-command as a valid boundary and add a regression for the no-argument e form.
			'/^sed\\b(?:\\s+-\\S+)*\\s+(?:(?:\\d+|\\$|\\/(?:\\\\.|[^\\/])+\\/)(?:\\s*,\\s*(?:\\d+|\\$|\\/(?:\\\\.|[^\\/])+\\/))?)?\\s*!?\\s*[erRwW]\\s/': false,

src/vs/platform/agentHost/node/commandAutoApprover.ts:653

  • This still auto-approves the valid GNU sed script sed e (and therefore a pipeline such as printf 'id\n' | sed e). With no command argument, e executes the current pattern space, but the unquoted matcher requires trailing whitespace, so the subcommand falls through to sed: true. Treat end-of-command as a valid boundary and add a regression for the no-argument e form.
	'/^sed\\b(?:\\s+-\\S+)*\\s+(?:(?:\\d+|\\$|\\/(?:\\\\.|[^\\/])+\\/)(?:\\s*,\\s*(?:\\d+|\\$|\\/(?:\\\\.|[^\\/])+\\/))?)?\\s*!?\\s*[erRwW]\\s/': false,
  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread src/vs/platform/agentHost/node/commandAutoApprover.ts Outdated
@anthonykim1
anthonykim1 marked this pull request as draft August 5, 2026 17:48
Skip operands consumed by line-length options, keep escaped quotes inside the
script scan, allow empty regex addresses, and recognize commands at end of
input.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 102bf1fe-34f3-4b81-b22f-5677ace2be4d
@anthonykim1
anthonykim1 marked this pull request as ready for review August 5, 2026 18:02
@anthonykim1
anthonykim1 enabled auto-merge (squash) August 5, 2026 18:02
@anthonykim1
anthonykim1 merged commit d5941c9 into main Aug 5, 2026
29 checks passed
@anthonykim1
anthonykim1 deleted the anthonykim1/sed-positional-script-auto-approve branch August 5, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants