npm search RCE? - Escape Sequence Injection
The npm CLI failed to properly sanitise escape sequences in package metadata, allowing terminal control sequences that could execute commands when a user runs 'npm search'.
Published on blog.solidsnail.com
How many programmers does it take to filter out 36 characters? You may think this is an opening to a joke, but it’s not.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the npm CLI used an inadequate regular expression (ansiTrim) to strip escape sequences, which did not cover all control characters and could be bypassed.
Impact
An attacker could potentially execute commands on a victim's machine if the victim uses a vulnerable terminal and runs 'npm search' for a malicious package.
What the attacker needed
Victim uses a vulnerable terminal; victim runs npm search on malicious package
The fix
The author suggests filtering out specific control characters before output.
How it was found
- Create a package with a malicious description containing escape sequences.
- Publish the package to a registry.
- Run 'npm search' for the package name.
- The escape sequences are printed to the terminal, potentially causing terminal control effects.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Terminals use special invisible characters called escape sequences to control things like colours and cursor position. If a program prints untrusted text without removing these characters, an attacker can hide commands that the terminal might execute. This report shows how the npm command-line tool failed to strip such characters from package descriptions.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.