Skip to content

Commit

Permalink
import: check if author is actually on pad before importing
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMcLear committed Apr 4, 2020
1 parent d2687f1 commit 9847bf6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions settings.json.docker
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@
"indentationOnNewLine": false,
*/

/*
* If true, importing to a pad is allowed only if an author has a session
* estabilished and has already contributed to that specific pad.
*/
"requireAuthorSessionToImport": true,

/*
* From Etherpad 1.8.3 onwards, the maximum allowed size for a single imported
* file is always bounded.
Expand Down
6 changes: 6 additions & 0 deletions settings.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@
"indentationOnNewLine": false,
*/

/*
* If true, importing to a pad is allowed only if an author has a session
* estabilished and has already contributed to that specific pad.
*/
"requireAuthorSessionToImport": true,

/*
* From Etherpad 1.8.3 onwards, the maximum allowed size for a single imported
* file is always bounded.
Expand Down
32 changes: 32 additions & 0 deletions src/node/hooks/express/importexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var settings = require('../../utils/Settings');
var exportHandler = require('../../handler/ExportHandler');
var importHandler = require('../../handler/ImportHandler');
var padManager = require("../../db/PadManager");
var authorManager = require("../../db/AuthorManager");

exports.expressCreateServer = function (hook_name, args, cb) {

Expand Down Expand Up @@ -47,6 +48,37 @@ exports.expressCreateServer = function (hook_name, args, cb) {
return next();
}

if (settings.requireAuthorSessionToImport) {
console.debug("Requiring an author session to import");
if (!req.cookies) {
console.warn("Unable to import file because no cookies included in request");
next();
}

if(!req.cookies.token) {
next();
}

let authorExists = await authorManager.getAuthor4Token(req.cookies.token);
if (!authorExists) {
console.warn("Unable to import file because Author does not exist");

return next();
}

let authorsPads = await authorManager.listPadsOfAuthor(authorExists);
if (!authorsPads) {
console.warn("Unable to import because author does exist but they are not on this pad");
return next();
}

let authorsPadIDs = authorsPads.padIDs;
if (authorsPadIDs.indexOf(req.params.pad) === -1) {
console.warn("Unable to import file because author exists but is not present on pad");
return next();
}
}

importHandler.doImport(req, res, req.params.pad);
}
});
Expand Down
6 changes: 6 additions & 0 deletions src/node/utils/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ exports.scrollWhenFocusLineIsOutOfViewport = {
*/
exports.exposeVersion = false;

/*
* If true, importing to a pad is allowed only if an author has a session
* estabilished and has already contributed to that specific pad.
*/
exports.requireAuthorSessionToImport = true;

/*
* From Etherpad 1.8.3 onwards, the maximum allowed size for a single imported
* file is always bounded.
Expand Down

0 comments on commit 9847bf6

Please sign in to comment.