@@ -8,7 +8,11 @@ const socket = require('socket.io')
8
8
const multer = require ( 'multer' )
9
9
const bodyParser = require ( 'body-parser' )
10
10
const cors = require ( 'cors' )
11
+ const helmet = require ( 'helmet' )
12
+ const hpp = require ( 'hpp' )
11
13
var winston = require ( './config/winston' )
14
+ const rateLimiter = require ( './app/middleware/rateLimiter' )
15
+ const sanitizer = require ( './app/middleware/sanitise' )
12
16
const fileConstants = require ( './config/fileHandlingConstants' )
13
17
14
18
const indexRouter = require ( './app/routes/index' )
@@ -23,13 +27,15 @@ const projectRouter = require('./app/routes/project')
23
27
const notificationRouter = require ( './app/routes/notification' )
24
28
const proposalRouter = require ( './app/routes/proposal' )
25
29
const analyticsRouter = require ( './app/routes/analytics' )
30
+ const activityRouter = require ( './app/routes/activity' )
26
31
27
32
const app = express ( )
28
33
const server = require ( 'http' ) . Server ( app )
29
34
30
35
app . use ( cors ( ) )
31
36
32
37
app . use ( bodyParser . json ( { limit : '200mb' } ) )
38
+ app . use ( cookieParser ( ) )
33
39
app . use ( bodyParser . urlencoded ( fileConstants . fileParameters ) )
34
40
35
41
const memoryStorage = multer . memoryStorage ( )
@@ -71,6 +77,23 @@ app.use((req, res, next) => {
71
77
next ( )
72
78
} )
73
79
80
+ // TO PREVENT DOS ATTACK AND RATE LIMITER
81
+ app . use ( rateLimiter . customRateLimiter )
82
+
83
+ // TO PREVENT XSS ATTACK
84
+ app . use ( sanitizer . cleanBody )
85
+ app . use ( helmet ( ) )
86
+
87
+ // TO PREVENT CLICK JACKING
88
+ app . use ( ( req , res , next ) => {
89
+ res . append ( 'X-Frame-Options' , 'Deny' )
90
+ res . set ( 'Content-Security-Policy' , "frame-ancestors 'none';" )
91
+ next ( )
92
+ } )
93
+
94
+ // TO PREVENT THE QUERY PARAMETER POLLUTION
95
+ app . use ( hpp ( ) )
96
+
74
97
app . use ( '/notification' , notificationRouter )
75
98
app . use ( '/' , indexRouter )
76
99
app . use ( '/auth' , authRouter )
@@ -83,6 +106,7 @@ app.use('/comment', commentRouter)
83
106
app . use ( '/project' , projectRouter )
84
107
app . use ( '/proposal' , proposalRouter )
85
108
app . use ( '/analytics' , analyticsRouter )
109
+ app . use ( '/activity' , activityRouter )
86
110
87
111
// catch 404 and forward to error handler
88
112
app . use ( function ( req , res , next ) {
@@ -102,7 +126,7 @@ app.use(function (err, req, res, next) {
102
126
103
127
// render the error page
104
128
res . status ( err . status || 500 )
105
- res . render ( 'error' )
129
+ res . render ( 'error' , { csrfToken : req . csrfToken ( ) } )
106
130
107
131
// Socket event error handler (On max event)
108
132
req . io . on ( 'error' , function ( err ) {
0 commit comments