Fix command chain approval bypass using shell-quote library#1
Fix command chain approval bypass using shell-quote library#1
Conversation
Co-authored-by: keith-hall <11882719+keith-hall@users.noreply.github.com>
|
@copilot Thanks, looking good. Let's fix it to ignore operators inside quoted strings, and escaped operators, for better usability |
Co-authored-by: keith-hall <11882719+keith-hall@users.noreply.github.com>
Done in dff61c1. The improved implementation now:
Added 9 new test cases covering these scenarios. All 2099 tests passing. |
|
@copilot Very nice, thanks! What do you think about replacing our custom character by character parsing with the sh-syntax npm package? It should give us less code to maintain while keeping all our test cases passing |
Co-authored-by: keith-hall <11882719+keith-hall@users.noreply.github.com>
Co-authored-by: keith-hall <11882719+keith-hall@users.noreply.github.com>
Excellent suggestion! Replaced our custom character-by-character parser with
The implementation is now more maintainable while keeping all functionality intact. |
Context
Auto-approval was checking entire command strings against patterns, allowing
cd backend && npm installwhen onlycdwas allowed. This enables privilege escalation by chaining permitted commands with unauthorized ones.Implementation
Core Changes:
splitCommandChain()to parse command chains by shell operators (&&,||,;,|)shell-quotelibrary for robust shell command parsing instead of custom implementation:getCommandApprovalDecision()to validate each command in the chain individuallyBenefits of using shell-quote:
Examples:
Test Coverage:
Screenshots
How to Test
execute.allowed: ["cd"]cd backend && npm installexecute.allowed: ["cd", "npm"]echo "test && quoted"withallowed: ["echo"]should approve (single command)echo test\;morewithallowed: ["echo"]should approve (single command)Or run the test suite:
Get in Touch
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.