Skip to content

Commit 630a8e1

Browse files
authored
feat: always ask for approval for non-readonly commands (#510)
1 parent 27895d6 commit 630a8e1

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

pkg/agent/conversation.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -936,13 +936,7 @@ func (c *Agent) analyzeToolCalls(ctx context.Context, toolCalls []gollm.Function
936936
if err != nil {
937937
toolCallAnalysis[i].IsInteractiveError = err
938938
}
939-
modifiesResourceStr := toolCall.GetTool().CheckModifiesResource(call.Arguments)
940-
if modifiesResourceStr == "unknown" {
941-
if llmModifies, ok := call.Arguments["modifies_resource"].(string); ok {
942-
modifiesResourceStr = llmModifies
943-
}
944-
}
945-
toolCallAnalysis[i].ModifiesResourceStr = modifiesResourceStr
939+
toolCallAnalysis[i].ModifiesResourceStr = toolCall.GetTool().CheckModifiesResource(call.Arguments)
946940
toolCallAnalysis[i].ParsedToolCall = toolCall
947941
}
948942
return toolCallAnalysis, nil

pkg/tools/kubectl_filter.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func kubectlModifiesResource(command string) string {
7171

7272
hasReadCommand := false
7373
foundWrite := false
74+
numCmds := 0
7475

7576
// Single pass through all command calls
7677
syntax.Walk(file, func(node syntax.Node) bool {
@@ -87,10 +88,21 @@ func kubectlModifiesResource(command string) string {
8788
if result == "no" {
8889
hasReadCommand = true
8990
}
91+
numCmds++
92+
if numCmds > 1 {
93+
return false // Stop walking if more then one command is found
94+
}
9095
}
9196
return true
9297
})
9398

99+
if numCmds > 1 {
100+
// if it's a composite bash command, we should err on the side of caution and return unknown
101+
// to prevent exfilteration attacks https://simonwillison.net/2025/Jun/16/the-lethal-trifecta/
102+
klog.Infof("KubectlModifiesResource result: unknown for command: %q, multiple commands (%d) found", command, numCmds)
103+
return "unknown"
104+
}
105+
94106
// Return results based on what we found
95107
if foundWrite {
96108
klog.Infof("KubectlModifiesResource result: yes (write operation found) for command: %q", command)

0 commit comments

Comments
 (0)