Fix readOnly pad export

The export request hook wasn't testing if the pad's id was from a read-only
pad before validating with the pad manager.

This includes an extra step that makes the read-only id verification and also
avoids setting the original pad's id as the file's name.
This commit is contained in:
Pedro Beschorner Marin 2020-09-16 14:57:27 -03:00 committed by John McLear
parent 9f63d9b76a
commit c56973ce74
3 changed files with 27 additions and 7 deletions

View file

@ -49,9 +49,10 @@ const tempDirectory = os.tmpdir();
/**
* do a requested export
*/
async function doExport(req, res, padId, type)
async function doExport(req, res, padId, readOnlyId, type)
{
var fileName = padId;
// avoid naming the read-only file as the original pad's id
var fileName = readOnlyId ? readOnlyId : padId;
// allow fileName to be overwritten by a hook, the type type is kept static for security reasons
let hookFileName = await hooks.aCallFirst("exportFileName", padId);
@ -130,9 +131,9 @@ async function doExport(req, res, padId, type)
}
}
exports.doExport = function(req, res, padId, type)
exports.doExport = function(req, res, padId, readOnlyId, type)
{
doExport(req, res, padId, type).catch(err => {
doExport(req, res, padId, readOnlyId, type).catch(err => {
if (err !== "stop") {
throw err;
}