2.0.0 • Published 4 years ago

@plastdev/security v2.0.0

Weekly downloads
1
License
ISC
Repository
gitlab
Last release
4 years ago

security

Sets Headers to a very save style. may be overriden by config.

Installation

  • npm install --save @plastdev/security

Usage

const security = require('@plastdev/security')
app.use(security(options))

Options

Headers

This is the List of Header with default values and Option name

HeaderOptionDefault Value
Cache-ControlCacheControlno-cache, no-store, must-revalidate
PragmaPragmano-cache
ExpiresExpires0
Content-Security-PolicyContentSecurityPolicydefault-src \'self\'; frame-ancestors \'none\'
X-XSS-ProtectionXXSSProtection1; mode=block
X-DNS-Prefetch-ControlXDNSPrefetchControloff
Expect-CTExpectCTreport-uri="/_report", enforce, max-age=30
X-Frame-OptionsXFrameOptionsdeny
X-Powered-ByXPoweredBytrue
Strict-Transport-SecurityStrictTransportSecuritymax-age=30
X-Download-OptionsXDownloadOptionsnoopen
X-Content-Type-OptionsXContentTypeOptionsnosniff
X-Permitted-Cross-Domain-PoliciesXPermittedCrossDomainPoliciesnone
Referrer-PolicyReferrerPolicyno-referrer

Allowed Methods

The option allowedMethods is an array of allowed HTTP-Methods.
By Default it is set to ['GET', 'POST', 'PUT', 'DELETE'], dissallowing e.g. HEAD

You may set this Array to whatever you like, we recommend to make it even more restrict if possible.

A read-only API may set allowedMethods: ['GET']

Only Defined Routes

The Option onlyDefinedRoutes may be set to true (Default: false)

Then only explicitely defined Routes are allowed by the express-Router, all other attempts will receive a status 405

To define Routes, use the Option definedRoutes, which expects an Array of Routes. No Wildcard is allowed as this kind of defeats the purpose of this ...

So if you have a route like /items/:id defined, you should add all ids to your array of defined routes ...

Examples

Run these and check with your favorite testing tool, eg nikto, zap

Default

You Should create SSL-Keys first to enable https-example:
openssl req -x509 -newkey rsa:4096 -keyout examples/default/private.key -out examples/default/certificate.crt -days 365 -nodes

node examples/default/index.js

unsave

node examples/unsave/index.js

Author

Dominik Sigmund dominik.sigmund@br.de

Contribution

Header

To add header, create a fork, then branch and add the header to:

  • index.js
  • index.test.js
  • README.md

then run tests and mutation tests.

after that, create a pull request and state the function of the header.

Other Functions

Similar as above, just make sure the functions secures the app even more.