-
You can escape root if there is a symlink withing the FTP, so creating a symlink inside the root such as |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments
-
Node's |
Beta Was this translation helpful? Give feedback.
-
Im able to navigate thru symlinks using this (and escape root doing so), it should be diisabled by default IMHO |
Beta Was this translation helpful? Give feedback.
-
Tried making these changes, although im still able to go thru the symlink and escape root with these changes (server on Linux, connecting thru Filezilla), am I missing something obvious? |
Beta Was this translation helpful? Give feedback.
-
Unless the client can create that symlink, the fact that the target folder is a link is a non-issue and should be the same as #167. You wouldn't be able to escape out of the linked folder into that location, it would still resolve to the location of the local filesystem. For example a file system like this;
and a server setup as:
The paths should resolve as; The fact that the FS is setup to use symlinks isn't the issue of the library, and I think is legitimate. @nfacha Am I describing what is happening here correctly? You are able to say, navigate to |
Beta Was this translation helpful? Give feedback.
-
@nfacha Can you checkout #224 and see if this resolves the issue you are having? |
Beta Was this translation helpful? Give feedback.
-
Symlinks can still be followed through, but can't escape in the way @forstermatth described above. |
Beta Was this translation helpful? Give feedback.
-
After checking out #224 i can still escape root on the following setup using FIlezilla If I switch into the symlink i can still see the server root and navigate thru the folders (that are outside the user root) From the PR changes it looks like you are appending the root path on the beginning, this is not enough tho, as going thru a symlink resolves the path with the root on the beginning already, after adding some logging(print out |
Beta Was this translation helpful? Give feedback.
-
I have sent in a PR (#226) that fixes root escaping thru symlinks. I don't usually work with node, so you might want to do some adjustments as while it works likely there is a better way to do it. |
Beta Was this translation helpful? Give feedback.
-
So, at the moment, we are not in agreement that this is an issue this library needs to be responsible for. My opinion is that, to prevent this issue, do not create the symlink in your filesystem. You are actively creating that symlink and making it available to your user. As an admin, there are legitimate uses for symlinks, and I think it is the server's responsibility to make sure the filesystem you are using is set up correctly. FTP clients cannot create these symlinks, so I don't think there is a security issue here. |
Beta Was this translation helpful? Give feedback.
-
This library enables creating a custom filesystem, you can use this to enable checking symlinks. You could overwrite the // symlinkCheckingFileSystem.js
const {FileSystem} = require('ftp-srv');
const isPathInside = require('is-path-inside'); // https://github.com/sindresorhus/is-path-inside
const {realPathSync} = require('fs');
module.exports.SymlinkCheckingFileSystem = class SymlinkCheckingFileSystem extends FileSystem {
constructor() {
super(...arguments);
}
_resolvePath(path) {
// Let base resolver do it's thing
const {clientPath, fsPath} = super._resolvePath(path);
// Resolve symlinks in path
const realFsPath = realPathSync(fsPath);
if (isPathInside(realFsPath, this.root)) {
// Oh no, this path escapes root!
throw new Error('Tsk tsk');
}
return {clientPath, fsPath};
}
} // index.js
const {FtpSrv} = require('ftp-srv');
const {SymlinkCheckingFileSystem} = require('./symlinkCheckingFileSystem.js');
const ftpServer = new FtpSrv();
ftpServer.on('login', (connection, resolve, reject) => {
// ...
resolve({
fs: new SymlinkCheckingFileSystem(connection, {root: '...', cwd: '...'}),
// ...
});
});
// ...
ftpServer.listen() This isn't something we want to do in the base library as |
Beta Was this translation helpful? Give feedback.
-
@heartz66 Please keep the discussion about symlinks here.
I'd like some more information as to the relevance of the pterodactyl game server, in regards to resolving symlinks in the context of an extensible FTP server. We have avoided making assumptions around the structure of the filesystem the user wants to expose, which can legitimately include symlinks (see above for an example). It is possible to write a resolution extension (example above) that removes the use of symlinks outside of the defined user root. But as far as we can tell, there is no reason to completely block the use of symlinks. |
Beta Was this translation helpful? Give feedback.
This library enables creating a custom filesystem, you can use this to enable checking symlinks.
You could overwrite the
_resolvePath
and perform a check there. Here's a quick example, not tested and probably doesn't work, but it gives you the idea.