A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.npmjs.com/package/express-secure-handlebars below:

express-secure-handlebars - npm

Express with Secure Handlebars

We enhance the express-handlebars server-side view engine by leveraging the secure-handlebars for defending against Cross-Site Scripting (XSS). Hence, web applications can be automatically secured by contextual output escaping.

For more details, kindly refer to the introductions to secure-handlebars and xss-filters.

Quick Start Installation

npm install express-secure-handlebars --save

Usage

Simply replace express-handlebars with the express-secure-handlebars package in all require()!

Basic Example

Based on the basic example of ExpressHandlebars, here we show an example app that can be secured only with our package.

views/profile.handlebars:

Given that there is a very typical handlebars template file written like so to incorporate user inputs. The enhanced package can secure the web application by automatically applying context-sensitive output filters, which otherwise is still subject to XSS attacks if using the default escaping approach (e.g., when url is javascript:alert(1) or onclick=alert(1)).

<h1>Example App: {{title}}</h1>

...

<div>User-provided URL: <a href="{{url}}">{{url}}</a></div>

...

views/layouts/main.handlebars:

Same as the Handlebars original example, this file serves as the HTML page wrapper which can be reused for the different views of the app. {{{body}}} is used as a placeholder for where the main content should be rendered.

<!DOCTYPE html>

<html>

<head><meta charset="utf-8"><title>{{title}}</title></head>

<body>

    {{{body}}}

</body>

</html>

app.js:

A super simple Express app that registers the Handlebars view engine.

var express = require('express'),

    exphbs  = require('express-secure-handlebars');

 

var app = express(),

    hbs = exphbs.create({  });

 

app.engine('handlebars', hbs.engine);

app.set('view engine', 'handlebars');

 

app.use('/profile', function (req, res) {

    res.render('profile', {

        title:  'User Profile',

        url:    req.query.url    

    });

});

 

app.listen(3000);

Development Known Limitations & Issues

Please refer to the section documented in secure-handlebars.

Warnings and Workarounds

Please refer to the section documented in secure-handlebars.

How to test

Apply your changes to files in src/, and then run the tests.

License

This software is free to use under the Yahoo Inc. BSD license. See the LICENSE file for license text and copyright information.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4