Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/sparcs-kaist/taxi-back into #…
Browse files Browse the repository at this point in the history
…273-안-읽은-메세지-확인
  • Loading branch information
chlehdwon committed Sep 3, 2023
2 parents 5369fe0 + 90de1a3 commit 63896a3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ app.use(require("./src/middlewares/limitRate"));
// [Router] Swagger (API 문서)
app.use("/docs", require("./src/routes/docs"));

// [Middleware] 모든 API 요청에 대하여 origin 검증
app.use(require("./src/middlewares/originValidator"));

// [Router] APIs
app.use("/auth", require("./src/routes/auth"));
app.use("/logininfo", require("./src/routes/logininfo"));
Expand Down
10 changes: 0 additions & 10 deletions src/middlewares/information.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
module.exports = (req, res, next) => {
req.clientIP = req.headers["x-forwarded-for"] || req.connection.remoteAddress;
req.timestamp = Date.now();
req.origin =
req.headers.origin ||
req.headers.referer ||
req.session?.loginAfterState?.redirectOrigin; // sparcssso/callback 요청은 헤더에 origin이 없음

if (!req.origin) {
return res.status(400).json({
error: "Bad Request : request must have origin in header",
});
}
next();
};
13 changes: 13 additions & 0 deletions src/middlewares/originValidator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = (req, res, next) => {
req.origin =
req.headers.origin ||
req.headers.referer ||
req.session?.loginAfterState?.redirectOrigin; // sparcssso/callback 요청은 헤더에 origin이 없음

if (!req.origin) {
return res.status(400).json({
error: "Bad Request : request must have origin in header",
});
}
next();
};
1 change: 1 addition & 0 deletions src/services/auth.replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const loginReplaceHandler = (req, res) => {
if (!loginAfterState)
return res.status(400).send("SparcsssoCallbackHandler : invalid request");
const { redirectOrigin, redirectPath } = loginAfterState;
req.session.loginAfterState = undefined;
tryLogin(req, res, createUserData(id), redirectOrigin, redirectPath);
};

Expand Down

0 comments on commit 63896a3

Please sign in to comment.