Renaming/aliasing relative symbolic links potentially redirects them to supposedly inaccessible locations
A relative symbolic link inside an allowed directory could be renamed or aliased so that it points outside the permitted directory tree, letting a Node.js process with the permission model enabled read files it should not access. In the worst case, an attacker could access any file on the system, though the impact is limited because the permission model already prevents creating new relative symlinks.
- Triaged in 23 days
- Disclosed after 4 months
If a relative symbolic link is accessible to the Node.js process while the permission model is enabled, it can be redirected to a different target by renaming/aliasing it, which potentially allows the process to bypass restrictions imposed by the permission model.
Steps To Reproduce:
- Let's begin with a trusted directory structure.
git clone -b v20.0.0 --depth 1 https://github.com/nodejs/node.git node-20
cd node-20
-
Now enter a Node.js REPL that (supposedly) only has access to the current working directory:
CONSOLE node --experimental-permission --allow-fs-read=$(pwd) --allow-fs-write=$(pwd) -
Now either
renameorlinkan existing relative symbolic link to redirect it. Example:JavaScript fs.renameSync('tools/node_modules/eslint/node_modules/eslint', 'escape'); fs.readdirSync('escape'); // Prints the contents of the (supposedly inaccessible) parent directory.
Conveniently, tools/node_modules/eslint/node_modules/eslint is a symbolic link that points to its parent directory. As long as it remains in its original location, that is, of course, not a problem. In fact, relative symbolic links are very common, especially on Linux systems, and the symbolic link's target is well within the directory structure that the process is allowed to access. Once renamed, however, the symbolic link points outside of said directory structure.
Impact
Of course, this depends on the pre-existing directory structure. In the worst case, this vulnerability allows an attacker to access any files on the system, regardless of restrictions imposed by the permission model.
This problem would be much more severe if not for another bug in the permission model, which prevents creating relative symbolic links altogether. Luckily, this other bug prevents the attacker from creating relative symlinks themselves, thus, they have to rely on existing relative symlinks (plus any created by package managers, etc.). Due to this fortunate restriction, I have not set the severity of the vulnerability to "high" but only to "medium".
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 permission model checks the path of a symbolic link rather than resolving its target after the link is moved, so a relative link can escape the allowed directory when renamed.
Impact
In the worst case, this vulnerability allows an attacker to access any files on the system, regardless of restrictions imposed by the permission model, though the impact is limited because the permission model prevents creating new relative symbolic links.
What the attacker needed
Node.js with permission model enabled; An existing relative symbolic link in an allowed directory; Ability to rename or link files
How it was found
- Clone the Node.js repository at version 20.0.0 and enter the directory.
- Start a Node.js REPL with the experimental permission model allowing read and write only to the current working directory.
- Rename an existing relative symbolic link to a new name, which changes its target relative to the new location.
- Read the renamed link to access the contents of the parent directory, which should be inaccessible.
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 symbolic link is like a shortcut that points to another file or folder. Node.js has a security feature that restricts which folders a program can read or write. This report shows that if a shortcut inside an allowed folder is moved, it can end up pointing to a folder outside the allowed area, letting the program see files it should not. The attacker needs an existing relative shortcut to abuse this.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.