Skip to content

Commit 56411ca

Browse files
committed
Make HSTS behaviour configurable; Fixes #584
1 parent 53c2d0b commit 56411ca

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Application settings `config.json`
166166
| port | `80` | web app port |
167167
| alloworigin | `['localhost']` | domain name whitelist |
168168
| usessl | `true` or `false` | set to use ssl server (if true will auto turn on `protocolusessl`) |
169+
| hsts | `{"enable": "true", "maxAgeSeconds": "31536000", "includeSubdomains": "true", "preload": "true"}` | [HSTS](https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security) options to use with HTTPS (default is the example value, max age is a year) |
169170
| protocolusessl | `true` or `false` | set to use ssl protocol for resources path (only applied when domain is set) |
170171
| urladdport | `true` or `false` | set to add port on callback url (port 80 or 443 won't applied) (only applied when domain is set) |
171172
| usecdn | `true` or `false` | set to use CDN resources or not (default is `true`) |

app.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,16 @@ var sessionStore = new SequelizeStore({
9797
app.use(compression())
9898

9999
// use hsts to tell https users stick to this
100-
app.use(helmet.hsts({
101-
maxAge: 31536000 * 1000, // 365 days
102-
includeSubdomains: true,
103-
preload: true
104-
}))
100+
if (config.hsts.enable) {
101+
app.use(helmet.hsts({
102+
maxAge: config.hsts.maxAgeSeconds * 1000,
103+
includeSubdomains: config.hsts.includeSubdomains,
104+
preload: config.hsts.preload
105+
}))
106+
} else if (config.usessl) {
107+
logger.info('Consider enabling HSTS for extra security:')
108+
logger.info('https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security')
109+
}
105110

106111
i18n.configure({
107112
locales: ['en', 'zh', 'fr', 'de', 'ja', 'es', 'ca', 'el', 'pt', 'it', 'tr', 'ru', 'nl', 'hr', 'pl', 'uk', 'hi', 'sv', 'eo', 'da'],

config.json.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
}
77
},
88
"development": {
9+
"hsts": {
10+
"enable": false
11+
},
912
"db": {
1013
"dialect": "sqlite",
1114
"storage": "./db.hackmd.sqlite"
1215
}
1316
},
1417
"production": {
1518
"domain": "localhost",
19+
"hsts": {
20+
"enable": "true",
21+
"maxAgeSeconds": "31536000",
22+
"includeSubdomains": "true",
23+
"preload": "true"
24+
},
1625
"db": {
1726
"username": "",
1827
"password": "",

lib/config/default.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ module.exports = {
77
urladdport: false,
88
alloworigin: ['localhost'],
99
usessl: false,
10+
hsts: {
11+
enable: true,
12+
maxAgeSeconds: 31536000,
13+
includeSubdomains: true,
14+
preload: true
15+
},
1016
protocolusessl: false,
1117
usecdn: true,
1218
allowanonymous: true,

0 commit comments

Comments
 (0)