@staticcms/proxy-server-lite
Version:
Proxy server to be used with Static CMS proxy backend
26 lines • 1.07 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pathTraversal = void 0;
const joi_1 = __importDefault(require("joi"));
const path_1 = __importDefault(require("path"));
function pathTraversal(repoPath) {
return joi_1.default.extend({
type: 'path',
base: joi_1.default.string().required(),
messages: {
'path.invalid': '{{#label}} must resolve to a path under the configured repository',
},
validate(value, helpers) {
const resolvedRepoPath = path_1.default.join(repoPath, '');
const resolvedPath = path_1.default.join(repoPath, value);
if (!resolvedPath.startsWith(resolvedRepoPath)) {
return { value, errors: helpers.error('path.invalid') };
}
},
}).path();
}
exports.pathTraversal = pathTraversal;
//# sourceMappingURL=customValidators.js.map