Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fi-aegis

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fi-aegis

Web Application Security Middleware.

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Fi Aegis

Build Status npm version

Web Application Security Middleware

This fork is based on lusca v1.4.1 but has changed greatly since.

The most relevant changes are minor optimizations, code refactoring and improved documentation with the addition of some functionality.

Installation

Fi Aegis is available only as an NPM package.

Install using:

npm install fi-aegis

Remember to add the --save modifier if you're using an NPM version lower than 5.x.x.

Usage

const session = require('express-session');
const express = require('express');
const aegis = require('fi-aegis');

const app = express();

/* This or other session management will be required */
app.use(session({
  secret: 'abc',
  resave: true,
  saveUninitialized: true
}));

app.use(aegis({
  csrf: true,
  csp: {
    angular: true
  },
  xframe: 'SAMEORIGIN',
  p3p: 'ABCDEF', /*[DEPRECATED]*/
  hsts: {
    maxAge: 31536000,
    includeSubDomains: true,
    preload: true
  },
  xssProtection: true,
  nosniff: true
}));

Setting any value to false will disable it. Alternately, you can opt into methods one by one:

app.use(aegis.csrf());
app.use(aegis.csp({ angular: true }));
app.use(aegis.xframe('SAMEORIGIN'));
app.use(aegis.p3p('ABCDEF')); /*[DEPRECATED]*/
app.use(aegis.hsts({ maxAge: 31536000 }));
app.use(aegis.xssProtection(true));
app.use(aegis.nosniff());

Please note that you must use express-session, cookie-session, their express 3.x alternatives, or other session object management in order to use Fi Aegis.

API

Cross-Site Request Forgery

Status

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.

Furthermore, parsers must be registered before Fi Aegis.

Usage:
aegis.csrf(options);
Options:
ParamTypeRequiredDefaultDescription
keyStringNo_csrfThe name of the CSRF token added to the model.
secretStringNo_csrfSecretThe key to place on the session object which maps to the server side token.
implFunctionNoSee lib/token.js.Custom implementation to generate a token.
angularBooleanNofalseShorthand setting to set Fi Aegis up to use the default settings for CSRF validation according to the AngularJS docs.
cookieString or ObjectYes (if angular is false)NoneIf set, a cookie with the name you provide will be set with the CSRF token.
cookie.nameStringYes (if angular is false and cookie is Object)NoneThe name you provide will be set as the cookie with the CSRF token.
cookie.optionsObjectNoNoneA valid Express cookie options object. See Express response cookies for more information.
headerStringYes (if angular is false)NoneIf set, the header name you provide will be set with the CSRF token.

Content Security Policy

Status

Enables Content Security Policy (CSP) headers.

See the MDN CSP usage page for more information on available policy options.

See the AngularJS ngCsp directive docs to learn the how to implement it when using CSP on your server.

Usage:
aegis.csp(options);
Options:
ParamTypeRequiredDefaultDescription
policyString, Object or ArrayYesEmptyObject definition of policy. Valid policies examples include.
reportOnlyBooleanNofalseEnable report only mode.
reportUriStringNoEmptyURI where to send the report data
Example Options:

Everything but images can only come from own domain (excluding subdomains):

{
  policy: {
    'default-src': '\'self\'',
    'img-src': '*'
  }
}

Pre-existing site that uses too much inline code to fix but wants to ensure resources are loaded only over https and disable plugins:

{
  policy: 'default-src https: \'unsafe-inline\'; object-src \'none\''
}

Load images only through HTTPS and from self domain and upgrade all insecure requests:

{
  policy: [
    {
      'img-src': '\'self\' https:'
    },

    'upgrade-insecure-requests'
  ]
}

See MDN CSP Headers for more examples and directives.


X-Frame-Options

Status

Enables X-FRAME-OPTIONS headers to help prevent Clickjacking.

See MDN X-Frame-Options docs to learn more about it.

Usage:
aegis.xframe(value);
Value:
ParamTypeRequiredDefaultDescription
valueStringYesNoneThe value for the header, e.g. DENY, SAMEORIGIN or ALLOW-FROM uri.

HTTP Strict Transport Security

Status

Enables HTTP Strict Transport Security for the host domain. The preload flag is required for HSTS domain submissions to Chrome's HSTS preload list.

See MDN Strict-Transport-Security for more information.

Usage:
aegis.hsts(options);
Options:
ParamTypeRequiredDefaultDescription
maxAgeNumberYesNoneNumber of seconds HSTS is in effect.
includeSubDomainsBooleanNoNoneApplies HSTS to all subdomains of the host.
preloadBooleanNoNoneAdds preload flag. This is not part of the specification. See this for more details about why.

X-Content-Type-Options

Status

Enables X-Content-Type-Options header to prevent MIME-sniffing a response away from the declared content-type.

Usage:
aegis.nosniff();

X-XSS-Protection

Status

Enables X-XSS-Protection headers to help prevent cross site scripting (XSS) attacks in older IE browsers (IE8).

Usage:
aegis.xssProtection(options);
Options:
ParamTypeRequiredDefaultDescription
enabledBooleanNo1If the header is enabled or not.
modeStringNoblockMode to set on the header.

Platform for Privacy Preferences (P3P) Project

Status

Enables Platform for Privacy Preferences (P3P) Project headers.

The development of P3P has been suspended. This is still available in order to maintain compatibility. See Platform for Privacy Preferences (P3P) Project on W3C for more information.

Usage:
aegis.p3p(value);
Value:
ParamTypeRequiredDefaultDescription
valueStringYesNoneThe compact privacy policy.

Keywords

FAQs

Package last updated on 28 Jul 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc