Skip to content

Commit a876d58

Browse files
committed
Enhance application security and logging
- Set the Express app to trust proxy headers for improved request handling. - Add middleware to return a 404 status for specific WordPress-related routes. - Update unauthorized error logging to include the socket IP address along with the original request IP and forwarded IP.
1 parent c1ba832 commit a876d58

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
2121
const publicPath = path.join(__dirname, "public");
2222

2323
const app = express();
24+
app.set("trust proxy", true);
2425

2526
const sessionManager = new SessionManager();
2627
app.locals.sessionManager = sessionManager;
@@ -39,6 +40,10 @@ if (config.nodeEnv !== "production") {
3940
app.use(express.static(publicPath));
4041
app.use(requestLogger);
4142

43+
app.use(["/wp-admin/*", "/wordpress/*", "/*.php"], (_req, res) => {
44+
res.status(404).end();
45+
});
46+
4247
app.use("/docs", docsRouter);
4348
app.use("/health", healthRouter);
4449
app.use("/.well-known", wellKnownRouter);

src/middleware/auth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function sendUnauthorized(
3333
errorType: "auth",
3434
code,
3535
message,
36-
ip: req.ip || req.headers["x-forwarded-for"],
36+
ip: req.ip,
37+
forwardedFor: req.headers["x-forwarded-for"],
38+
socketIp: req.socket.remoteAddress,
3739
userAgent: req.headers["user-agent"],
3840
method: req.method,
3941
path: req.path,

0 commit comments

Comments
 (0)