@reldens/server-utils 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/app-server-factory.js +38 -27
- package/package.json +2 -2
|
@@ -13,7 +13,7 @@ const session = require('express-session');
|
|
|
13
13
|
const rateLimit = require('express-rate-limit');
|
|
14
14
|
const cors = require('cors');
|
|
15
15
|
const helmet = require('helmet');
|
|
16
|
-
const
|
|
16
|
+
const sanitizeHtml = require('sanitize-html');
|
|
17
17
|
|
|
18
18
|
class AppServerFactory
|
|
19
19
|
{
|
|
@@ -26,30 +26,29 @@ class AppServerFactory
|
|
|
26
26
|
this.appServer = false;
|
|
27
27
|
this.app = express();
|
|
28
28
|
this.rateLimit = rateLimit;
|
|
29
|
-
this.useCors =
|
|
30
|
-
this.useExpressJson =
|
|
31
|
-
this.useUrlencoded =
|
|
32
|
-
this.encoding =
|
|
33
|
-
this.useHttps =
|
|
34
|
-
this.passphrase =
|
|
35
|
-
this.httpsChain =
|
|
36
|
-
this.keyPath =
|
|
37
|
-
this.certPath =
|
|
38
|
-
this.trustedProxy =
|
|
39
|
-
this.windowMs =
|
|
40
|
-
this.maxRequests =
|
|
41
|
-
this.applyKeyGenerator =
|
|
42
|
-
this.jsonLimit =
|
|
43
|
-
this.urlencodedLimit =
|
|
44
|
-
this.useHelmet =
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
);
|
|
29
|
+
this.useCors = true;
|
|
30
|
+
this.useExpressJson = true;
|
|
31
|
+
this.useUrlencoded = true;
|
|
32
|
+
this.encoding = 'utf-8';
|
|
33
|
+
this.useHttps = false;
|
|
34
|
+
this.passphrase = '';
|
|
35
|
+
this.httpsChain = '';
|
|
36
|
+
this.keyPath = '';
|
|
37
|
+
this.certPath = '';
|
|
38
|
+
this.trustedProxy = '';
|
|
39
|
+
this.windowMs = 60000;
|
|
40
|
+
this.maxRequests = 30;
|
|
41
|
+
this.applyKeyGenerator = false;
|
|
42
|
+
this.jsonLimit = '1mb';
|
|
43
|
+
this.urlencodedLimit = '1mb';
|
|
44
|
+
this.useHelmet = true;
|
|
45
|
+
this.helmetConfig = false;
|
|
46
|
+
this.useXssProtection = true;
|
|
47
|
+
this.globalRateLimit = 0;
|
|
48
|
+
this.corsOrigin = '*';
|
|
49
|
+
this.corsMethods = ['GET','POST'];
|
|
50
|
+
this.corsHeaders = ['Content-Type','Authorization'];
|
|
51
|
+
this.tooManyRequestsMessage = 'Too many requests, please try again later.';
|
|
53
52
|
this.error = {};
|
|
54
53
|
this.processErrorResponse = false;
|
|
55
54
|
}
|
|
@@ -60,7 +59,7 @@ class AppServerFactory
|
|
|
60
59
|
Object.assign(this, appServerConfig);
|
|
61
60
|
}
|
|
62
61
|
if(this.useHelmet){
|
|
63
|
-
this.app.use(helmet());
|
|
62
|
+
this.app.use(this.helmetConfig ? helmet(this.helmetConfig) : helmet());
|
|
64
63
|
}
|
|
65
64
|
if(this.useCors){
|
|
66
65
|
let corsOptions = {
|
|
@@ -86,7 +85,19 @@ class AppServerFactory
|
|
|
86
85
|
this.app.use(this.rateLimit(limiterParams));
|
|
87
86
|
}
|
|
88
87
|
if(this.useXssProtection){
|
|
89
|
-
this.app.use(
|
|
88
|
+
this.app.use((req, res, next) => {
|
|
89
|
+
if(!req.body){
|
|
90
|
+
return next();
|
|
91
|
+
}
|
|
92
|
+
if(typeof req.body === 'object'){
|
|
93
|
+
for(let key in req.body){
|
|
94
|
+
if(typeof req.body[key] === 'string'){
|
|
95
|
+
req.body[key] = sanitizeHtml(req.body[key]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
next();
|
|
100
|
+
});
|
|
90
101
|
}
|
|
91
102
|
if(this.useExpressJson){
|
|
92
103
|
this.app.use(this.applicationFramework.json({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reldens/server-utils",
|
|
3
3
|
"scope": "@reldens",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"description": "Reldens - Server Utils",
|
|
6
6
|
"author": "Damian A. Pastorini",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"express-session": "1.18.1",
|
|
43
43
|
"helmet": "8.1.0",
|
|
44
44
|
"multer": "^1.4.5-lts.2",
|
|
45
|
-
"
|
|
45
|
+
"sanitize-html": "^2.16.0"
|
|
46
46
|
}
|
|
47
47
|
}
|