Skip to content

Commit

Permalink
Add rate limiting to auth-related endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
kthchew committed Feb 3, 2024
1 parent 30d57ef commit 7a2cc85
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
15 changes: 15 additions & 0 deletions Backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cors": "^2.8.5",
"dotenv": "^16.4.1",
"express": "^4.18.2",
"express-rate-limit": "^7.1.5",
"mongodb": "^6.3.0"
},
"devDependencies": {
Expand Down
10 changes: 8 additions & 2 deletions Backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ const cors = require('cors');
const axios = require('axios');
const {connectToServer, getDb} = require('./db/conn.js')

const RateLimit = require('express-rate-limit');
const limiter = RateLimit({
windowMs: 15 * 60 * 1000,
max: 100,
});

const app = express();
app.use(cors());

Expand Down Expand Up @@ -114,7 +120,7 @@ app.get('/getSubmission', async (req, res) => {
})


app.get('/logout', async (req, res) => {
app.get('/logout', limiter, async (req, res) => {
const user_id = req.query.user_id;

let db = getDb();
Expand All @@ -123,7 +129,7 @@ app.get('/logout', async (req, res) => {
res.status(200).json({ message: "Logged out!" });
})

app.get('/login', async (req, res) => {
app.get('/login', limiter, async (req, res) => {
const user_id = req.query.user_id;

let db = getDb();
Expand Down

0 comments on commit 7a2cc85

Please sign in to comment.