UNPKG

twing

Version:

First-class Twig engine for Node.js

50 lines (49 loc) 2.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeCheckSecurityNodeSynchronously = exports.executeCheckSecurityNode = void 0; const runtime_1 = require("../error/runtime"); const executeCheckSecurityNode = (node, executionContext) => { const { template, environment, sandboxed } = executionContext; const { usedTags, usedFunctions, usedFilters } = node.attributes; if (sandboxed) { const issue = environment.sandboxPolicy.checkSecurity([...usedTags.keys()], [...usedFilters.keys()], [...usedFunctions.keys()]); if (issue !== null) { const { type, token } = issue; let node; if (type === "tag") { node = usedTags.get(token); } else if (type === "filter") { node = usedFilters.get(token); } else { node = usedFunctions.get(token); } throw (0, runtime_1.createRuntimeError)(issue.message, node, template.source); } } return Promise.resolve(); }; exports.executeCheckSecurityNode = executeCheckSecurityNode; const executeCheckSecurityNodeSynchronously = (node, executionContext) => { const { template, environment, sandboxed } = executionContext; const { usedTags, usedFunctions, usedFilters } = node.attributes; if (sandboxed) { const issue = environment.sandboxPolicy.checkSecurity([...usedTags.keys()], [...usedFilters.keys()], [...usedFunctions.keys()]); if (issue !== null) { const { type, token } = issue; let node; if (type === "tag") { node = usedTags.get(token); } else if (type === "filter") { node = usedFilters.get(token); } else { node = usedFunctions.get(token); } throw (0, runtime_1.createRuntimeError)(issue.message, node, template.source); } } }; exports.executeCheckSecurityNodeSynchronously = executeCheckSecurityNodeSynchronously;