OWASP ESAPI Encoder for Node.js

0.0.1 · abandoned · verified Sun Apr 19

node-esapi is a minimal port of the OWASP Enterprise Security API for JavaScript (ESAPI4JS) encoder, adapted for use in Node.js environments. Published as version 0.0.1, it primarily offers functions for various output encoding contexts such as HTML, CSS, JavaScript, URL, HTML attributes, and Base64, aiming to mitigate Cross-Site Scripting (XSS) and other injection vulnerabilities. The package appears to have been developed around 2014, given its copyright, and has not seen subsequent releases or updates, indicating it is no longer actively maintained. While ESAPI was historically a key project for security, current best practices often recommend highly contextual encoding provided by templating engines or dedicated, well-maintained security libraries tailored to specific frameworks, rather than a generic, standalone encoder like this unmaintained port. Its core differentiator was being an OWASP-backed security utility, but its current state makes it unsuitable for modern applications.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of the ESAPI encoder to mitigate common injection vulnerabilities by encoding input for different contexts like HTML, JavaScript, and URLs.

const ESAPI = require('node-esapi');

// Get an encoder instance
const encoder = ESAPI.encoder();

// Example of HTML encoding
const userInput = '<script>alert("XSS!")</script>';
const encodedHTML = encoder.encodeForHTML(userInput);
console.log('Encoded for HTML:', encodedHTML);

// Example of JavaScript encoding
const jsInput = "hello' + world";
const encodedJS = encoder.encodeForJS(jsInput);
console.log('Encoded for JavaScript:', encodedJS);

// Example of URL encoding
const urlInput = 'http://example.com?param=value with spaces';
const encodedURL = encoder.encodeForURL(urlInput);
console.log('Encoded for URL:', encodedURL);

view raw JSON →