Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

PUBLIC / surfer-okd

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit d755925f authored 9 years ago by Johannes Zellner's avatar Johannes Zellner
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

Properly check for absolute file paths

1 parent 24545229
Show whitespace changes
Inline Side-by-side
Showing with 4 additions and 1 deletions
  • cli/actions.js
  • src/files.js
cli/actions.js
View file @d755925
...@@ -187,6 +187,7 @@ function del(filePath) { ...@@ -187,6 +187,7 @@ function del(filePath) {
superagent.del(config.server() + API + relativeFilePath).query(gQuery).end(function (error, result) { superagent.del(config.server() + API + relativeFilePath).query(gQuery).end(function (error, result) {
if (error && error.status === 401) return console.log('Login failed'); if (error && error.status === 401) return console.log('Login failed');
if (error && error.status === 404) return console.log('No such file or directory'); if (error && error.status === 404) return console.log('No such file or directory');
if (error && error.status === 403) return console.log('No such file or directory');
if (error) return console.log('Failed', result ? result.body : error); if (error) return console.log('Failed', result ? result.body : error);
console.log('Success. Removed %s files.', result.body.entries.length); console.log('Success. Removed %s files.', result.body.entries.length);
......
This diff is collapsed. Click to expand it.
src/files.js
View file @d755925
...@@ -106,7 +106,9 @@ function del(req, res, next) { ...@@ -106,7 +106,9 @@ function del(req, res, next) {
var filePath = req.params[0]; var filePath = req.params[0];
var absoluteFilePath = getAbsolutePath(filePath); var absoluteFilePath = getAbsolutePath(filePath);
if (!absoluteFilePath) return next(new HttpError(404, 'Not found')); if (!absoluteFilePath) return next(new HttpError(404, 'Not found'));
if (absoluteFilePath.slice(gBasePath.length) === '') return next(new HttpError(403, 'Forbidden'));
// absoltueFilePath has to have the base path prepended
if (absoluteFilePath.length <= gBasePath.length) return next(new HttpError(403, 'Forbidden'));
fs.stat(absoluteFilePath, function (error, result) { fs.stat(absoluteFilePath, function (error, result) {
if (error) return next(new HttpError(404, error)); if (error) return next(new HttpError(404, error));
......
This diff is collapsed. Click to expand it.
  • Write
  • Preview
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
  • Please register or sign in to post a comment