agent: Fix repeated 404 requests to malformed '/)' path

This commit is contained in:
platform-mcp
2026-06-17 20:15:35 +05:30
parent 9a523c038c
commit 7f3d94178d
4 changed files with 31 additions and 2 deletions
+12
View File
@@ -61,6 +61,18 @@ export const onRequest = defineMiddleware(async (context, next) => {
const method = context.request.method;
const path = context.url.pathname;
// Normalize paths corrupted by a trailing stray ")" before routing.
// These come from monitors/links that captured a URL together with a
// closing parenthesis — e.g. "https://workroot.in/)" copied out of the
// markdown/shell form "(https://workroot.in/)". Without this, every such
// probe hits a non-existent route and 404s on a loop (recurring "GET /)").
// Stripping the trailing paren(s) lets the request resolve to the intended
// route (e.g. "/)" -> "/"), so the monitor gets a 301 -> 200 instead.
const normalizedPath = path.replace(/\)+$/, '');
if (normalizedPath !== path && normalizedPath.length > 0) {
return context.redirect(`${normalizedPath}${context.url.search}`, 301);
}
// CSRF origin validation for API mutations
if (!validateCsrfOrigin(context.request, context.url)) {
logger.warn('middleware', 'CSRF origin check failed', {