Remote code execution in cdnjs of Cloudflare
The cdnjs library update server extracted npm tarballs without sanitising filenames, allowing path traversal. An attacker could overwrite regularly executed scripts and achieve remote code execution, potentially compromising cdnjs and tampering libraries served to many websites.
2021-07-16 1885 字 cdnjs Vulnerability Go Supply Chain RCE
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
What the attacker needed
Ability to publish an npm package; cdnjs update server processes the package
The fix
The vulnerability was fixed by sanitising filenames during tar extraction and by handling symlinks properly when copying files from Git repositories.
How it was found
- Publish a .tgz file containing a crafted filename to the npm registry.
- Wait for the cdnjs library update server to process the crafted .tgz file.
- The contents of the file are written into a regularly executed script file, and arbitrary commands are executed.
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.
The cdnjs service automatically downloads code packages from npm and unpacks them. The unpacking code did not check that file names inside the package stayed inside the intended folder, so a malicious package could write files anywhere on the server. By overwriting a script that runs regularly, an attacker could run their own commands on the server.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.