Web application security middleware for the latest koa 2.x.
Fork from koa-lusca,
It's a pity that koa-lusca is out of maintenances for over 3 years, so i made this fork and re-released it as koa-luscax, and let's keep it fresh.
const Koa = require('koa');
const lusca = require('koa-luscax');
const app = new Koa();
app.use(lusca({
csrf: true,
csp: { /* ... */},
xframe: 'SAMEORIGIN',
p3p: 'ABCDEF',
hsts: { maxAge: 31536000, includeSubDomains: true },
xssProtection: true,
referrerPolicy: 'same-origin'
}));
Setting any value to false
will disable it. Alternately, you can opt into methods one by one:
app.use(lusca.csrf());
app.use(lusca.csp({/* ... */}));
app.use(lusca.xframe({ value: 'SAMEORIGIN' }));
app.use(lusca.p3p({ value: 'ABCDEF' }));
app.use(lusca.hsts({ maxAge: 31536000 });
app.use(lusca.xssProtection();
app.use(lusca.referrerPolicy('same-origin'));
key
String - Optional. The name of the CSRF token added to the model. Defaults to_csrf
.secret
String - Optional. The key to place on the session object which maps to the server side token. Defaults to_csrfSecret
.impl
Function - Optional. Custom implementation to generate a token.
Enables Cross Site Request Forgery (CSRF) headers.
If enabled, the CSRF token must be in the payload when modifying data or you will receive a 403 Forbidden. To send the token you'll need to echo back the _csrf
value you received from the previous request.
options.policy
Object - Object definition of policy.options.policy
String, Object, or an Array - Object definition of policy. Valid policies examples include:{"default-src": "*"}
"referrer no-referrer"
[{ "img-src": "'self' http:" }, "block-all-mixed-content"]
options.reportOnly
Boolean - Enable report only mode.options.reportUri
String - URI where to send the report data
Enables Content Security Policy (CSP) headers.
// Everything but images can only come from own domain (excluding subdomains)
{
policy: {
'default-src': '\'self\'',
'img-src': '*'
}
}
See the MDN CSP usage page for more information on available policy options.
value
String - Required. The value for the header, e.g. DENY, SAMEORIGIN or ALLOW-FROM uri.
Enables X-FRAME-OPTIONS headers to help prevent Clickjacking.
value
String - Required. The compact privacy policy.
Enables Platform for Privacy Preferences Project (P3P) headers.
options.maxAge
Number - Required. Number of seconds HSTS is in effect.options.includeSubDomains
Boolean - Optional. Applies HSTS to all subdomains of the host
Enables HTTP Strict Transport Security for the host domain. The preload flag is required for HSTS domain submissions to Chrome's HSTS preload list
options.enabled
Boolean - Optional. If the header is enabled or not (see header docs). Defaults to1
.options.mode
String - Optional. Mode to set on the header (see header docs). Defaults toblock
.
Enables X-XSS-Protection headers to help prevent cross site scripting (XSS) attacks in older IE browsers (IE8)
Enables X-Content-Type-Options header to prevent MIME-sniffing a response away from the declared content-type.
value
String - Optional. The value for the header, e.g.origin
,same-origin
,no-referrer
. Defaults to `` (empty string).
Enables Referrer-Policy header to control the Referer header.
- Original License: Apache License, Version 2.0, Copyright (C) 2014 eBay Software Foundation
- Now: MIT
- Jeff Harrell jeff@juxtadesign.com (https://github.com/jeffharrell)
- Jeff Harrell jeharrell@paypal.com
- Erik Toth ertoth@paypal.com
- rragan rragan@ebay.com
- skoranga skoranga@paypal.com
- Lenny Markus lmarkus@paypal.com (https://github.com/lmarkus)
- totherik totherik@gmail.com
- Lenny Markus lensam69@yahoo.com
- Trevor tlivings@gmail.com
- Steve Stedman sstedman@paypal.com
- AlexSantos santosam72@gmail.com
- mstuart stuartmark@gmail.com
- swesthafer swesthafer@paypal.com
- Dmitry Shirokov deadrunk@gmail.com (https://github.com/runk)
- Sahat Yalkabov sakhat@gmail.com
- fengmk2 fengmk2@gmail.com (https://github.com/fengmk2)
- Anant Singh anantsingh@paypal.com
- Aria Stewart aredridel@dinhe.net (https://github.com/aredridel)
- Jean-Charles Sisk jasisk@gmail.com
- Matt Edelman medelman@paypal.com
- Ilya Radchenko ilya@burstcreations.com
- Poornima Venkat pvenkatakrishnan@paypal.com
- ali-sdk m@fengmk2.com (https://github.com/ali-sdk)
- fundon cfddream@gmail.com
- Christoffer Hallas hallas@users.noreply.github.com
- Geller geller@Gellers-MacBook-Pro.local
- Marek Fajkus marek.faj@gmail.com (https://github.com/turboMaCk)
- Shawn shaoshuai0102@gmail.com (https://github.com/shaoshuai0102)
- Chris Veness chrisv@movable-type.co.uk