Race Condition in Grunt
GruntJS's file.copy operations are vulnerable to a time-of-check to time-of-use race condition, allowing an attacker to write arbitrary files. A lower-privileged user with write access to both source and destination directories could exploit this to escalate privileges to the GruntJS user, potentially replacing sensitive files like .bashrc or /etc/shadow.
gruntjs/grunt
Originally disclosed on huntr
file.copy operations in GruntJS are vulnerable to a TOCTOU race condition leading to arbitrary file write in GitHub repository gruntjs/grunt prior to 1.5.3. This vulnerability is capable of arbitrary file writes which can lead to local privilege escalation to the GruntJS user if a lower-privileged user has write access to both source and destination directories as the lower-privileged user can create a symlink to the GruntJS user's .bashrc file or replace /etc/shadow file if the GruntJS user is root.
From the GitHub Advisory Database (GHSA-rm36-94g8-835r, CC BY 4.0).
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the file copy operation checks the source file and then copies it without ensuring the file hasn't been replaced by a symlink in between, leading to a TOCTOU race condition.
Impact
An attacker with write access to both source and destination directories could write arbitrary files, potentially escalating privileges to the GruntJS user, including root if Grunt runs as root.
What the attacker needed
Write access to source directory; write access to destination directory; GruntJS user runs with higher privileges
The fix
The vulnerability was fixed in version 1.5.3.
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 report has not been written yet. The Original tab links to the source.
A race condition happens when a program checks something and then uses it, but an attacker can change it in between. Here, Grunt checks a file and then copies it, but an attacker can swap the file for a symbolic link (a shortcut) to a sensitive file, causing Grunt to overwrite that file instead. This can let a less privileged user gain the permissions of the user running Grunt.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.