
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
context-parser-handlebars
Advanced tools
This pre-compiler is to automatically conduct HTML 5 context analysis on Handlebars templates, and insert markup of XSS filtering helpers to output expressions based on their surrounding contexts.
The resulted templates can then be further processed with the vanilla Handlebars template engine. With the context-sensitive helpers properly registered at runtime, the context-sensitive escaping will effectively defend against XSS attacks.
Install the context-parser-handlebars npm globally, so it can be used in any project.
npm install context-parser-handlebars -g
Given a handlebars template file like so:
<html><title>{{title}}</title></html>
Run through the handlebars template file with our Handlebars Context Pre-compiler, and you can see that context-sensitive helpers are added to output expressions like so:
$ handlebarspc <handlebars template file>
<html><title>{{{yd title}}}</title></html>
The resulted pre-compiled template file is fully-compatible with the vanilla Handlebars. See secure-handlebars-helpers on how to register the corresponding helpers on the client-side for context-sensitive filtering.
Note: the default context-insensitive HTML escaping by Handlebars is disabled with the raw {{{expression}}} to prevent redundant escaping.
Analyze the HTML contexts of Handlebars templates on server-side.
// create the precompiler
var ContextParserPreCompiler = require("context-parser-handlebars");
var preCompiler = new ContextParserPreCompiler();
// given data stores a handlebars template as string
var data = '<html><title>{{title}}</title></html>';
try {
// analyze the HTML contexts
preCompiler.contextualize(data);
// return a processed handlebars template with context-sensitive helpers added!
// i.e., output is '<html><title>{{{yd title}}}</title></html>';
var output = preCompiler.getOutput();
// ...
} catch (err) {
// ...
}
// ...
npm test
This software is free to use under the BSD license. See the LICENSE file for license text and copyright information.
FAQs
Handlebars Context PreCompiler
The npm package context-parser-handlebars receives a total of 2 weekly downloads. As such, context-parser-handlebars popularity was classified as not popular.
We found that context-parser-handlebars demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.