MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / isCommandList

Function isCommandList

source code/utils/bash/commands.ts:541–605  ·  view source on GitHub ↗
(command: string)

Source from the content-addressed store, hash-verified

539
540// Checks if this is just a list of commands
541function isCommandList(command: string): boolean {
542 // Generate unique placeholders for this parse to prevent injection attacks
543 const placeholders = generatePlaceholders()
544
545 // Extract heredocs before parsing - shell-quote parses << incorrectly
546 const { processedCommand } = extractHeredocs(command)
547
548 const parseResult = tryParseShellCommand(
549 processedCommand
550 .replaceAll('"', `"${placeholders.DOUBLE_QUOTE}`) // parse() strips out quotes :P
551 .replaceAll("'", `'${placeholders.SINGLE_QUOTE}`), // parse() strips out quotes :P
552 varName => `$${varName}`, // Preserve shell variables
553 )
554
555 // If parse failed, it's not a safe command list
556 if (!parseResult.success) {
557 return false
558 }
559
560 const parts = parseResult.tokens
561 for (let i = 0; i < parts.length; i++) {
562 const part = parts[i]
563 const nextPart = parts[i + 1]
564 if (part === undefined) {
565 continue
566 }
567
568 if (typeof part === 'string') {
569 // Strings are safe
570 continue
571 }
572 if ('comment' in part) {
573 // Don't trust comments, they can contain command injection
574 return false
575 }
576 if ('op' in part) {
577 if (part.op === 'glob') {
578 // Globs are safe
579 continue
580 } else if (COMMAND_LIST_SEPARATORS.has(part.op)) {
581 // Command list separators are safe
582 continue
583 } else if (part.op === '>&') {
584 // Redirection to standard input/output/error file descriptors is safe
585 if (
586 nextPart !== undefined &&
587 typeof nextPart === 'string' &&
588 ALLOWED_FILE_DESCRIPTORS.has(nextPart.trim())
589 ) {
590 continue
591 }
592 } else if (part.op === '>') {
593 // Output redirections are validated by pathValidation.ts
594 continue
595 } else if (part.op === '>>') {
596 // Append redirections are validated by pathValidation.ts
597 continue
598 }

Callers 1

Calls 4

generatePlaceholdersFunction · 0.85
extractHeredocsFunction · 0.85
tryParseShellCommandFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected