Skip to content
Snippets Groups Projects
Commit 53b64634 authored by Jesus Galaz's avatar Jesus Galaz
Browse files

Trying to fix vulnerability issues

parent aae4119e
No related branches found
No related tags found
1 merge request!6Adding toDo app functionability
Pipeline #15726 passed
...@@ -2,6 +2,7 @@ const express = require('express'); ...@@ -2,6 +2,7 @@ const express = require('express');
const path = require('path'); const path = require('path');
const connectDB = require('./mongodb'); const connectDB = require('./mongodb');
const session = require('express-session'); const session = require('express-session');
const url = require('url');
const app = express(); const app = express();
...@@ -9,6 +10,20 @@ const app = express(); ...@@ -9,6 +10,20 @@ const app = express();
app.use(express.json()); app.use(express.json());
app.use(express.static(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public')));
// Allow only localhost for SSRF protection
function validateLocalhost(req, res, next) {
const remoteAddress = req.connection.remoteAddress;
// Allow requests only from localhost (IPv4 and IPv6)
if (remoteAddress !== '127.0.0.1' && remoteAddress !== '::1') {
return res.status(403).send('External requests are forbidden');
}
next();
}
app.use(validateLocalhost); // Add the middleware
// Session configuration // Session configuration
app.use( app.use(
session({ session({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment