Skip to content

Commit 0f9de02

Browse files
committed
v1.0.2
1 parent c103c56 commit 0f9de02

2 files changed

Lines changed: 27 additions & 172 deletions

File tree

README.md

Lines changed: 24 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
# Blockade ⚓️
1+
# Blockade
22

3-
Blockade ⚓️ is a lightweight package that adds optional security headers for Node web frameworks.
3+
[![version](https://img.shields.io/npm/v/blockade.svg)](https://www.npmjs.com/package/blockade)
4+
[![Types](https://img.shields.io/npm/types/blockade.svg)](https://www.npmjs.com/package/blockade)
5+
[![License](https://img.shields.io/npm/l/blockade.svg)](https://www.npmjs.com/package/blockade)
6+
[![Style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
47

5-
### Supported Node.js web frameworks:
6-
[Express](https://expressjs.com), [hapi](https://hapijs.com), [Koa](https://koajs.com)
8+
Blockade ⚓️ is a lightweight package that adds optional security headers and cookie attributes for Node.js web frameworks.
79

10+
### Supported Node.js web frameworks:
11+
[AdonisJs](https://adonisjs.com), [Express](https://expressjs.com), [hapi](https://hapijs.com), [Koa](https://koajs.com), [Meteor](https://www.meteor.com), [Nest](https://nestjs.com), [Sails](https://sailsjs.com), [Total.js](https://www.totaljs.com)
812

913
## Install
1014

1115
```console
12-
$ nom install blockade
16+
$ npm i blockade
1317
```
1418

1519
After installing Blockade:
@@ -18,60 +22,15 @@ After installing Blockade:
1822
const blockade = require("blockade");
1923

2024
const secureHeaders = new blockade.SecureHeaders();
21-
```
22-
23-
## Security Headers
24-
25-
Security Headers are HTTP response headers that, when set, can enhance the security of your web application by enabling browser security policies.
26-
27-
You can assess the security of your HTTP response headers at [securityheaders.com](https://securityheaders.com)
28-
29-
*Recommendations used by Secure 🔒 and more information regarding security headers can be found at the [OWASP Secure Headers Project](https://www.owasp.org/index.php/OWASP_Secure_Headers_Project).*
30-
31-
## Headers
32-
33-
#### Server
34-
Contain information about server software
35-
**Default Value:** `NULL` *(obfuscate server information, not included by default)*
25+
const secureCookie = new blockade.SecureCookie();
3626

37-
#### Strict-Transport-Security (HSTS)
38-
Ensure application communication is sent over HTTPS
39-
**Default Value:** `max-age=63072000; includeSubdomains`
40-
41-
#### X-Frame-Options (XFO)
42-
Disable framing from different origins (clickjacking defense)
43-
**Default Value:** `SAMEORIGIN`
44-
45-
#### X-XSS-Protection
46-
Enable browser cross-site scripting filters
47-
**Default Value:** `1; mode=block`
48-
49-
#### X-Content-Type-Options
50-
Prevent MIME-sniffing
51-
**Default Value:** `nosniff`
52-
53-
#### Content-Security-Policy (CSP)
54-
Prevent cross-site injections
55-
**Default Value:** `script-src 'self'; object-src 'self'` *(not included by default)**
56-
57-
#### Referrer-Policy
58-
Enable full referrer if same origin, remove path for cross origin and disable referrer in unsupported browsers
59-
**Default Value:** `no-referrer, strict-origin-when-cross-origin`
60-
61-
#### Cache-control / Pragma / Expires
62-
Prevent cacheable HTTPS response
63-
**Default Value:** `no-cache, no-store, must-revalidate, max-age=0` / `no-cache` / `0`
27+
```
6428

65-
#### Feature-Policy
66-
Disable browser features and APIs
67-
**Default Value:** `accelerometer 'none'; ambient-light-sensor 'none'; autoplay 'none'; camera 'none'; encrypted-media 'none'; fullscreen 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; midi 'none'; payment 'none'; picture-in-picture 'none'; speaker 'none'; sync-xhr 'none'; usb 'none'; vr 'none';",` *(not included by default)*
6829

69-
### Additional information:
70-
- The `Strict-Transport-Security` (HSTS) header will tell the browser to **only** utilize secure HTTPS connections for the domain, and in the default configuration, including *all* subdomains. The HSTS header requires trusted certificates and users will *unable* to connect to the site if using self-signed or expired certificates. The browser will honor the HSTS header for the time directed in the max-age attribute (default = 2 years), and setting the max-age to 0 will disable an already set HSTS header. Use the `{ hsts: false }` option to not include the HSTS header in Secure Headers.
71-
- The `Content-Security-Policy` (CSP) header can break functionality and can (and should) be carefully constructed, use the `{ csp : true }` option to enable default values.
30+
## Secure Headers
7231

7332
### Example
74-
`secureHeaders.framework(response)`
33+
`secureHeaders.framework(response);`
7534

7635
**Default HTTP response headers:**
7736

@@ -86,129 +45,25 @@ Pragma: no-cache
8645
Expires: 0
8746
```
8847

89-
### Options
90-
91-
You can toggle the setting of headers with default values by passing an object with `true` or `false` and override default values by passing a string to the following options:
48+
## Secure Cookie
9249

93-
- `server` - set the Server header, e.g. `Server=“Secure”` *(string / bool, default=false)*
94-
- `hsts` - set the Strict-Transport-Security header *(string / bool, default=true)*
95-
- `xfo` - set the X-Frame-Options header *(string / bool, default=true)*
96-
- `xxp` - set the X-XSS-Protection header *(string / bool, default=true)*
97-
- `content` - set the X-Content-Type-Options header *(string / bool, default=true)*
98-
- `csp` - set the Content-Security-Policy *(string / bool, default=false)* *
99-
- `referrer` - set the Referrer-Policy header *(string / bool, default=true)*
100-
- `cache` - set the Cache-control and Pragma headers *(string / bool, default=true)*
101-
- `feature` - set the Feature-Policy header *(string / bool, default=false)*
102-
103-
#### Example
50+
### Example
10451

10552
```javascript
106-
const blockade = require("blockade");
107-
108-
const secureHeaders = new blockade.SecureHeaders({
109-
server: "Blockade",
110-
csp: true,
111-
hsts: false
112-
});
113-
114-
. . .
115-
116-
secureHeaders.framework(response)
117-
53+
secureCookie.framework(response, "foo", "bar");
11854
```
11955

120-
**HTTP response headers:**
121-
122-
```HTTP
123-
Server: Blockade
124-
X-Frame-Options: SAMEORIGIN
125-
X-XSS-Protection: 1; mode=block
126-
X-Content-Type-Options: nosniff
127-
Content-Security-Policy: script-src 'self'; object-src 'self'
128-
Referrer-Policy: no-referrer, strict-origin-when-cross-origin
129-
Pragma: no-cache
130-
Expires: 0
131-
Cache-control: no-cache, no-store, must-revalidate, max-age=0
132-
```
133-
134-
# Supported Frameworks
135-
136-
## Express
137-
138-
#### Headers
139-
`secureHeaders.express(res);`
140-
141-
##### Example
142-
```javascript
143-
const express = require("express");
144-
const blockade = require("blockade");
145-
146-
const secureHeaders = new blockade.SecureHeaders();
147-
. . .
148-
149-
app.use(function(req, res, next) {
150-
secureHeaders.express(res);
151-
next();
152-
});
153-
154-
. . .
155-
156-
```
157-
158-
## hapi
159-
160-
#### Headers
161-
`secureHeaders.hapi(response);`
162-
163-
##### Example
164-
```javascript
165-
const Hapi = require("hapi");
166-
const blockade = require("blockade");
167-
168-
const secureHeaders = new blockade.SecureHeaders();
169-
. . .
170-
171-
server.ext("onPreResponse", (request, h) => {
172-
const response = request.response;
173-
secureHeaders.hapi(response);
174-
return response;
175-
});
176-
177-
. . .
178-
179-
```
180-
181-
## Koa
182-
183-
#### Headers
184-
`secureHeaders.koa(ctx);`
185-
186-
##### Example
187-
```javascript
188-
const Koa = require("koa");
189-
const blockade = require("blockade");
190-
191-
const secureHeaders = new blockade.SecureHeaders();
192-
. . .
193-
194-
app.use(async (ctx, next) => {
195-
await next();
196-
secureHeaders.koa(ctx);
197-
});
198-
199-
. . .
56+
**Default Set-Cookie HTTP response header:**
20057

58+
```HTTP
59+
Set-Cookie: foo=bar; Path=/; secure; HttpOnly; SameSite=lax
20160
```
20261

62+
## Documentation
63+
Please see the full set of documentation at [https://blockadejs.readthedocs.io](https://blockadejs.readthedocs.io)
20364

204-
## Attribution/References
205-
206-
#### Frameworks
207-
- [Express](https://github.com/expressjs/express) - Fast, unopinionated, minimalist web framework for node.
208-
- [hapi](https://github.com/hapijs/hapi) - Server Framework for Node.js
209-
- [Koa.js](https://github.com/koajs) - Next generation web framework for Node.js
210-
211-
#### Resources
65+
## Resources
21266
- [OWASP - Secure Headers Project](https://www.owasp.org/index.php/OWASP_Secure_Headers_Project)
67+
- [OWASP - Session Management Cheat Sheet](https://www.owasp.org/index.php/Session_Management_Cheat_Sheet#Cookies)
21368
- [Mozilla Web Security](https://infosec.mozilla.org/guidelines/web_security)
214-
- [securityheaders.com](https://securityheaders.com)
69+
- [securityheaders.com](https://securityheaders.com)

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "blockade",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"repository": {
55
"type": "git",
6-
"url": "https://github.com/cakinney/blockade"
6+
"url": "https://github.com/TypeError/blockade"
77
},
8-
"description": "Security Headers for Node.js",
8+
"description": "Security Headers and Cookies for Node.js",
99
"main": "lib/blockade.js",
1010
"types": "lib/blockade.d.ts",
1111
"scripts": {

0 commit comments

Comments
 (0)