Skip to content

Commit 8126f7f

Browse files
Handle unknown routes to avoid stack traces leaks
1 parent ae38d86 commit 8126f7f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

components/server/src/express-util.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ export function unhandledToError(req: express.Request, res: express.Response, ne
7373
if (isAnsweredRequest(req, res)) {
7474
return next();
7575
}
76-
return next(new Error("unhandled request: " + req.method + " " + req.originalUrl));
76+
/* Handle unknown routes gracefully to improve user experience and security.
77+
* - Use a 404 status to indicate a "Not Found" error.
78+
* - Provide a clear and informative message to guide the user.
79+
* - Avoid exposing stack traces to prevent potential security vulnerabilities.
80+
* Note: Detailed error logging is delegated to the `bottomErrorHandler()` function.
81+
*/
82+
res.status(404).send(
83+
"Resource Not Accessible: The content you're attempting to access may have been removed, renamed, or is temporarily unavailable. Kindly verify the URL and retry.",
84+
);
7785
}
7886

7987
/**

0 commit comments

Comments
 (0)