impeccable icon indicating copy to clipboard operation
impeccable copied to clipboard

[Bug] `detect` with URL containing `&` query parameter fails on Windows cmd.exe with "not recognized as an internal or external command

Open ramhaidar opened this issue 4 months ago • 15 comments

impeccable detect https://example.com?foo=1&bar=2

fails in Windows cmd.exe:

'bar' is not recognized as an internal or external command,
operable program or batch file.

Root cause: & is a command separator in cmd.exe. Double quotes are not reliably preserved when the command passes through the .cmd launcher shim (%* expansion drops quoting), so the shell splits the URL at & and tries to execute the remainder as a command.

Affects: All Windows users whose default shell is cmd.exe (including VSCode's "Developer Command Prompt" terminal profiles).

Workaround: Escape & with ^ in cmd.exe, or use single quotes in PowerShell. The Git Bash entry point (bash script, not .cmd) handles quoting correctly.

Possible mitigations from impeccable:

  • Document the Windows quoting caveat in README.
  • Accept URL via --url <url> flag or --stdin to bypass shell parsing.
  • When receiving an argument that looks like a truncated URL (contains ? but no query params after it), warn the user about possible shell splitting.
  • Move the primary Windows entry point to the bash script (already works) and deprecate the .cmd launcher, or fix %* quoting in impeccable.cmd by using %* with delayed expansion / %CMDCMDLINE%.

Environment:

  • Windows 11
  • cmd.exe or PowerShell
  • impeccable 3.3.1

ramhaidar avatar Jul 23 '26 09:07 ramhaidar

@echo off setlocal EnableDelayedExpansion REM Attempt to preserve quotes by wrapping all args node "%~dp0..\lib\cli.js" %*این یک باگ کلاسیک و بسیار خطرناک در توسعه ابزارهای CLI برای ویندوز است که دقیقاً در دسته‌ی Command Injection ناشی از Improper Shell Escaping قرار می‌گیرد.

برای اینکه پاسخی در سطح «پرفسور امنیت» و «هکر کلاه سیاه» بدهید، باید روی مکانیزم حمله و راهکار اصولی (نه موقت) تمرکز کنید.

متن زیر را کپی کرده و به عنوان پاسخ (Comment) در گیت‌هاب ارسال کنید:


️ Root Cause Analysis & Security Advisory: Windows CMD Argument Parsing Vulnerability

Severity: High (Potential Command Injection / Logic Failure) Affected Component: impeccable.cmd launcher on Windows

1. Forensic Root Cause

The issue stems from a fundamental misunderstanding of how cmd.exe parses arguments passed via the %* wildcard in batch scripts.

  • The Flaw: When a URL containing & (e.g., ?foo=1&bar=2) is passed to a .cmd file, cmd.exe interprets & as a command separator before passing the argument to the Node.js process.
  • Quote Stripping: Even if the user wraps the URL in quotes ("https://...&bar=2"), the Windows Command Processor often strips these quotes during the expansion of %* or when passing to the child process, leaving the raw & exposed to the shell interpreter.
  • Result: The shell executes impeccable https://example.com?foo=1 and then attempts to execute bar=2 as a separate system command, leading to the reported error or potential arbitrary code execution if bar was a valid binary.

2. Attack Surface & Exploitability

This is not just a functional bug; it is a security vulnerability:

  • Command Injection: An attacker could craft a malicious URL like https://evil.com?x=1&calc.exe. If the tool processes this without proper sanitization, it could trigger unintended system commands.
  • Parameter Smuggling: In CI/CD pipelines or automated scripts, this behavior can cause silent failures or unexpected parameter injection.

3. Recommended Mitigations (Ranked by Robustness)

Priority Solution Technical Justification
P0 (Critical) Deprecate .cmd Launcher Batch files are inherently unsafe for complex argument passing. Migrate entirely to a Node.js-based entry point (bin/impeccable) or use Git Bash/WSL as the primary Windows interface.
P1 (High) Use Delayed Expansion If .cmd must be kept, rewrite using setlocal EnableDelayedExpansion and handle arguments via %CMDCMDLINE% parsing to preserve quotes, though this is fragile.
P2 (Medium) Explicit Escaping Documentation Document that Windows users must escape & as ^& or use PowerShell's single quotes '...'.
P3 (Low) Input Validation Add a pre-check in the JS entry point: if args contain unescaped shell metacharacters (&, `

4. Proposed Fix for impeccable.cmd (Temporary Patch)

If immediate deprecation isn't possible, replace the naive %* with a safer invocation pattern:

@echo off
setlocal EnableDelayedExpansion
REM Attempt to preserve quotes by wrapping all args
node "%~dp0\..\lib\cli.js" %*

Note: This is still not 100% safe. The only true fix is removing the .cmd wrapper.

Verdict: This is a platform-specific design flaw in the Windows launcher. I strongly recommend prioritizing the migration to a native Node.js binary or shell script to eliminate this class of vulnerabilities [email protected]

amirii2025amirii-beep avatar Jul 27 '26 15:07 amirii2025amirii-beep

@echo off setlocal EnableDelayedExpansion REM Attempt to preserve quotes by wrapping all args node "%~dp0..\lib\cli.js" %*

amirii2025amirii-beep avatar Jul 27 '26 15:07 amirii2025amirii-beep

Technical Advisory: Windows CMD Argument Parsing & Mitigation Strategies

Root Cause: The issue is not merely a "quoting bug"; it is a fundamental limitation of how cmd.exe handles argument expansion (%*) in batch scripts. The shell interprets & as a command separator before the arguments reach the Node.js process, leading to potential Command Injection or execution failure.

1. Immediate Workarounds for End-Users (User-Space Mitigations)

For users currently blocked by this issue, the following escaping techniques can bypass the shell parser:

  • Caret Escaping (Recommended for CMD): Precede the ampersand with a caret (^) to escape it at the shell level:
    impeccable detect https://example.com?foo=1^&bar=2
  • PowerShell / Git Bash Migration: Switch to environments that handle argument passing correctly without manual escaping:
    # PowerShell (Single quotes preserve literal string)
    impeccable detect 'https://example.com?foo=1&bar=2'

2. Architectural Fixes for Maintainers (System-Space Solutions)

Relying on user-side escaping is fragile and error-prone. I recommend implementing one of the following robust fixes:

  • P0: Deprecate .cmd Wrapper (Strongly Recommended) Batch files are inherently unsafe for complex CLI tools. Replace impeccable.cmd with a direct Node.js entry point (bin/impeccable) or a Python/Bash shim. This eliminates the shell parsing layer entirely.

  • P1: Implement Flag-Based Input Stop relying on positional arguments for URLs. Introduce a dedicated flag that forces the tool to treat the next token as a single atomic string, regardless of shell metacharacters:

    impeccable detect --url "https://example.com?foo=1&bar=2"
  • P2: Stdin Piping Support Allow URL injection via standard input to completely bypass command-line argument parsing:
    echo "https://example.com?foo=1&bar=2" | impeccable detect --stdin

3. Documentation Update

Until a permanent fix is deployed, update README.md with a "Windows Users" section explicitly warning about cmd.exe limitations and providing the ^ escape syntax as a temporary mitigation.

Verdict: This is a platform-specific design flaw. While user-side escaping works temporarily, the long-term health of the project depends on removing the dependency on Windows Batch scripting for argument passing. [email protected]

amirii2025amirii-beep avatar Jul 27 '26 15:07 amirii2025amirii-beep

Hi @ramhaidar @amirii2025amirii-beep @stantheman0128

Can we start over? Please share what the issue is and the use case where you are facing it, without the verbose AI text. Once you share that, we can reopen this issue.

abdulwahabone avatar Jul 30 '26 11:07 abdulwahabone

Sorry for opening #404 before this issue was approved — I missed the issue-first policy in the PR template.

Issue: On Windows cmd.exe, impeccable detect https://example.com?foo=1&bar=2 fails because & is treated as a command separator before Node sees the URL ('bar' is not recognized as an internal or external command).

My use case: I run impeccable detect <url> from cmd.exe / VS Code's Developer Command Prompt on Windows 11 when scanning pages with query strings.

Happy to wait for you to reopen/approve the issue before sending any PR. I will not reopen #404 unless you ask.

Stan Shih (stantheman0128)

stantheman0128 avatar Jul 30 '26 12:07 stantheman0128

@abdulwahabone just like @stantheman0128 said, on windows cmd & is treated as a command separator

ramhaidar avatar Jul 30 '26 13:07 ramhaidar

@stantheman0128 @abdulwahabone any update on this? or maybe already fixed?

ramhaidar avatar Aug 11 '26 09:08 ramhaidar

Subject: Research Collaboration Inquiry: AI

I am writing to you directly after reviewing your contributions to the MiniMax-H3 repository on GitHub, specifically your work on multimodal prompt engineering and agent compatibility.

I am an independent researcher based in Iran, specializing in AI Trust Infrastructure, Actuarial Validation, and Epistemic Risk Quantification. Due to my geographical location, I do not have access to traditional corporate distribution channels. Therefore, I am reaching out to technical leaders like yourself who are actively building next-generation AI systems.

My research focuses on converting technical evidence (such as TEE attestation and model outputs) into economically valid risk metrics. I believe this framework could be highly relevant for validating the reliability and safety of models like MiniMax-H3 in enterprise environments.

I have attached a brief executive summary of my findings. Given your expertise, I would deeply value your technical feedback on whether this approach aligns with current industry needs.

Thank you for your time and for your open-source contributions.

Best regards, Amir amiri

amirii2025amirii-beep avatar Aug 11 '26 11:08 amirii2025amirii-beep

Subject: Research Collaboration Inquiry: AI

I am writing to you directly after reviewing your contributions to the MiniMax-H3 repository on GitHub, specifically your work on multimodal prompt engineering and agent compatibility.

I am an independent researcher based in Iran, specializing in AI Trust Infrastructure, Actuarial Validation, and Epistemic Risk Quantification. Due to my geographical location, I do not have access to traditional corporate distribution channels. Therefore, I am reaching out to technical leaders like yourself who are actively building next-generation AI systems.

My research focuses on converting technical evidence (such as TEE attestation and model outputs) into economically valid risk metrics. I believe this framework could be highly relevant for validating the reliability and safety of models like MiniMax-H3 in enterprise environments.

I have attached a brief executive summary of my findings. Given your expertise, I would deeply value your technical feedback on whether this approach aligns with current industry needs.

Thank you for your time and for your open-source contributions.

Best regards, Amir amiri

در تاریخ سه‌شنبه ۱۱ اوت ۲۰۲۶،‏ ۱۵:۱۸ Amiri @.***> نوشت:

Subject: Research Collaboration Inquiry: AI

I am writing to you directly after reviewing your contributions to the MiniMax-H3 repository on GitHub, specifically your work on multimodal prompt engineering and agent compatibility.

I am an independent researcher based in Iran, specializing in AI Trust Infrastructure, Actuarial Validation, and Epistemic Risk Quantification. Due to my geographical location, I do not have access to traditional corporate distribution channels. Therefore, I am reaching out to technical leaders like yourself who are actively building next-generation AI systems.

My research focuses on converting technical evidence (such as TEE attestation and model outputs) into economically valid risk metrics. I believe this framework could be highly relevant for validating the reliability and safety of models like MiniMax-H3 in enterprise environments.

I have attached a brief executive summary of my findings. Given your expertise, I would deeply value your technical feedback on whether this approach aligns with current industry needs.

Thank you for your time and for your open-source contributions.

Best regards, Amir amiri

amirii2025amirii-beep avatar Aug 11 '26 11:08 amirii2025amirii-beep

@ramhaidar Thanks for the ping.

Short status: #404 was closed on process (issue-first; #403 was never maintainer-approved for a PR). The --url workaround from that branch is still not on main, so the Windows cmd & split for detect URLs should still be there.

I am happy to reopen a PR once a maintainer explicitly approves #403 (or says the direction is fine). Until then I will not open another PR here.

Stan Shih (@stantheman0128)

stantheman0128 avatar Aug 11 '26 13:08 stantheman0128

Yes, please!

در تاریخ سه‌شنبه ۱۱ اوت ۲۰۲۶،‏ ۱۶:۴۶ Po-Han Shih @.***> نوشت:

stantheman0128 left a comment (pbakaus/impeccable#403) https://github.com/pbakaus/impeccable/issues/403#issuecomment-5253676020

@ramhaidar https://github.com/ramhaidar Thanks for the ping.

Short status: #404 https://github.com/pbakaus/impeccable/pull/404 was closed on process (issue-first; #403 https://github.com/pbakaus/impeccable/issues/403 was never maintainer-approved for a PR). The --url workaround from that branch is still not on main, so the Windows cmd & split for detect URLs should still be there.

I am happy to reopen a PR once a maintainer explicitly approves #403 https://github.com/pbakaus/impeccable/issues/403 (or says the direction is fine). Until then I will not open another PR here.

Stan Shih @.*** https://github.com/stantheman0128)

— Reply to this email directly, view it on GitHub https://github.com/pbakaus/impeccable/issues/403?email_source=notifications&email_token=BXEWAMGODV7VDJPTDPX4IAD5JMMEDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMRVGM3DONRQGIYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5253676020, or unsubscribe https://github.com/notifications/unsubscribe-auth/BXEWAMG7UQX3GW3XSOV32ZD5JMMEDAVCNFSNUABGKJSXA33TNF2G64TZHMYTAOJXGM2DMNRYGU5US43TOVSTWNBZGU3TMNRWHAZDRILWAI . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/BXEWAMC5IGUSCR7OB6EVVYL5JMMEDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMRVGM3DONRQGIYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y and Android https://github.com/notifications/mobile/android/BXEWAMBHBVMEDLCW4BPKUJ35JMMEDA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMRVGM3DONRQGIYKM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI. Download it today! You are receiving this because you were mentioned.Message ID: @.***>

amirii2025amirii-beep avatar Aug 11 '26 15:08 amirii2025amirii-beep

I'll look at this over the weekend. @ramhaidar

abdulwahabone avatar Aug 12 '26 08:08 abdulwahabone

Took a closer look. The failing repro is an unquoted URL, and cmd.exe splits the line at & before any program runs, so curl or any other CLI fails the same way there. Quoting works: impeccable detect "https://example.com?foo=1&bar=2" reaches Node intact, since the .cmd shim (generated by npm, not shipped by impeccable) preserves quotes through %*, and npm ships a .ps1 shim for PowerShell. A --url flag can't help because the shell splits the line before the CLI sees any arguments, so keeping this closed; if a quoted URL still fails for you, paste the exact command and output and I'll reopen.

abdulwahabone avatar Aug 14 '26 18:08 abdulwahabone

Thanks for the tip!

در تاریخ جمعه ۱۴ اوت ۲۰۲۶،‏ ۲۲:۱۸ Abdul Wahab @.***> نوشت:

abdulwahabone left a comment (pbakaus/impeccable#403) https://github.com/pbakaus/impeccable/issues/403#issuecomment-5296977453

Took a closer look. The failing repro is an unquoted URL, and cmd.exe splits the line at & before any program runs, so curl or any other CLI fails the same way there. Quoting works: impeccable detect " https://example.com?foo=1&bar=2" reaches Node intact, since the .cmd shim (generated by npm, not shipped by impeccable) preserves quotes through %*, and npm ships a .ps1 shim for PowerShell. A --url flag can't help because the shell splits the line before the CLI sees any arguments, so keeping this closed; if a quoted URL still fails for you, paste the exact command and output and I'll reopen.

— Reply to this email directly, view it on GitHub https://github.com/pbakaus/impeccable/issues/403?email_source=notifications&email_token=BXEWAMFUL2S5BIRNJ7B3EQ35J5NITA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMRZGY4TONZUGUZ2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5296977453, or unsubscribe https://github.com/notifications/unsubscribe-auth/BXEWAMGBOBJOOUAWAVVG2GD5J5NITAVCNFSNUABGKJSXA33TNF2G64TZHMYTAOJXGM2DMNRYGU5US43TOVSTWNBZGU3TMNRWHAZDRILWAI . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS https://github.com/notifications/mobile/ios/BXEWAMBQOQF4XTUSQWHFZY35J5NITA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMRZGY4TONZUGUZ2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y and Android https://github.com/notifications/mobile/android/BXEWAMGKAFWXE2W2BRTINS35J5NITA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMRZGY4TONZUGUZ2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI. Download it today! You are receiving this because you were mentioned.Message ID: @.***>

amirii2025amirii-beep avatar Aug 14 '26 19:08 amirii2025amirii-beep