agent: Fix repeated 404 requests to malformed '/)' path
This commit is contained in:
@@ -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', {
|
||||
|
||||
Reference in New Issue
Block a user