Skip to content

Commit

Permalink
Prevent error stack exposure in responses with status code 500
Browse files Browse the repository at this point in the history
  • Loading branch information
nunogoncalves03 committed Jan 25, 2024
1 parent 4be7057 commit 12e0110
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions backend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const morgan = require("morgan");
require("./auth/fenixOAuth2");
require("./auth/demoLocal");
const isLoggedIn = require("./middleware/isLoggedIn");
const { logger } = require("./modules/logging");
const { logger, logInfo } = require("./modules/logging");

const app = express();

Expand Down Expand Up @@ -49,13 +49,14 @@ app.use("/transactions", isLoggedIn, require("./routes/transactionRoutes"));
app.use("/users", isLoggedIn, require("./routes/userRoutes"));
app.use("/auth", require("./routes/authRoutes"));
app.use("/logs", isLoggedIn, require("./routes/logRoutes"));
app.use(require("./middleware/error").errorHandler);

app.get("/health", (req, res) => {
res.status(200).send("OK");
});

app.listen(process.env.PORT, () => {
console.log(`Server listening on port ${process.env.PORT}`);
logInfo("index", `Server listening on port ${process.env.PORT}`);
});

require("./cron/weeklyBackup");
Expand Down
2 changes: 1 addition & 1 deletion backend/src/middleware/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const errorHandler = (err, req, res, next) => {
if (!err) return next();

res.sendStatus(500);
logError("middleware/error", `${err}`);
logError("middleware/error", `${err.stack}`);
};

const asyncHandler = (fn) => (req, res, next) =>
Expand Down

0 comments on commit 12e0110

Please sign in to comment.