Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
if (request.route.settings.validate.failAction === 'ignore') {
return;
}
// Prepare error
const defaultError = validationError.isBoom ? validationError : Boom.badRequest(`Invalid request ${source} input`);
const detailedError = Boom.boomify(validationError, { statusCode: 400, override: false });
detailedError.output.payload.validation = { source, keys: [] };
if (validationError.details) {
for (const details of validationError.details) {
const path = details.path;
detailedError.output.payload.validation.keys.push(Hoek.escapeHtml(path.join('.')));
}
}
if (request.route.settings.validate.errorFields) {
for (const field in request.route.settings.validate.errorFields) {
detailedError.output.payload[field] = request.route.settings.validate.errorFields[field];
}
}
return request._core.toolkit.failAction(request, request.route.settings.validate.failAction, defaultError, { details: detailedError, tags: ['validation', 'error', source] });
};
Handlebars.registerHelper('lintJoin', (array) => {
let str = '';
for (let i = 0; i < array.length; ++i) {
if (str) {
str += '
'; // This is a line break
}
str += Hoek.escapeHtml(array[i]); // Handlebars' escape is just not enough
}
return new Handlebars.SafeString(str);
});
Handlebars.registerHelper('errorStack', (err) => {
const stack = err.stack.slice(err.stack.indexOf('\n') + 1).replace(/^\s*/gm, ' ');
return new Handlebars.SafeString(Hoek.escapeHtml(stack));
});
internals.generateListing = async function (path, resource, selection, hasTrailingSlash, settings, request) {
let files;
try {
files = await Fs.readdir(path);
}
catch (err) {
Bounce.rethrow(err, 'system');
throw Boom.internal('Error accessing directory', err);
}
resource = decodeURIComponent(resource);
const display = Hoek.escapeHtml(resource);
let html = '<title>' + display + '</title><h1>Directory: ' + display + '</h1><ul>';
if (selection) {
const parent = resource.substring(0, resource.lastIndexOf('/', resource.length - (hasTrailingSlash ? 2 : 1))) + '/';
html = html + '<li><a href="' + internals.pathEncode(parent) + '">Parent Directory</a></li>';
}
for (let i = 0; i < files.length; ++i) {
if (settings.showHidden ||
!internals.isFileHidden(files[i])) {
html = html + '<li><a href="' + internals.pathEncode(resource + (!hasTrailingSlash ? '/' : '') + files[i]) + '">' + Hoek.escapeHtml(files[i]) + '</a></li>';
}
}
html = html + '</ul>';
Handlebars.registerHelper('errorMessage', (err) => {
return new Handlebars.SafeString(Hoek.escapeHtml('' + err.message));
});
entry.errors.forEach((err) => {
err.message = Hoek.escapeHtml(err.message);
});
}, this);
}
resource = decodeURIComponent(resource);
const display = Hoek.escapeHtml(resource);
let html = '<title>' + display + '</title><h1>Directory: ' + display + '</h1><ul>';
if (selection) {
const parent = resource.substring(0, resource.lastIndexOf('/', resource.length - (hasTrailingSlash ? 2 : 1))) + '/';
html = html + '<li><a href="' + internals.pathEncode(parent) + '">Parent Directory</a></li>';
}
for (let i = 0; i < files.length; ++i) {
if (settings.showHidden ||
!internals.isFileHidden(files[i])) {
html = html + '<li><a href="' + internals.pathEncode(resource + (!hasTrailingSlash ? '/' : '') + files[i]) + '">' + Hoek.escapeHtml(files[i]) + '</a></li>';
}
}
html = html + '</ul>';
return request.generateResponse(html);
};