Skip to content

Commit

Permalink
Added security middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvaibhavmishra committed Dec 9, 2023
1 parent bf2a2a3 commit 477492a
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 8 deletions.
17 changes: 17 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import cors from "cors";
import cron from "node-cron";
import { spawn } from "child_process";

// security packages
import helmet from "helmet";
import { xss } from "express-xss-sanitizer";
import bodyParser from "body-parser";
import mongoSanitize from "express-mongo-sanitize";
import cookieParser from "cookie-parser";

import trainRouter from "./routes/train.js";
import authRouter from "./routes/authRoutes.js";

Expand All @@ -22,6 +29,16 @@ app.use(
})
);

// parsing data to json
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// security middlewares
app.use(helmet()); // general security
app.use(xss()); // xss protection
app.use(mongoSanitize()); // sanitization for mongodb
app.use(cookieParser()); // parsing cookies

// Connect to the MongoDB database
mongoose
.connect(process.env.MONGODB_URI)
Expand Down
Loading

1 comment on commit 477492a

@vercel
Copy link

@vercel vercel bot commented on 477492a Dec 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.