From cf49f405b0a8e565d5766e774cd57c9ae2184591 Mon Sep 17 00:00:00 2001 From: David Malchin Date: Sat, 11 Nov 2023 20:31:39 +0200 Subject: [PATCH] fix(REST): strip webhook tokens (#9723) * fix(REST): strip webhook tokens * fix(REST): implement requested changes Co-authored-by: ckohen --------- Co-authored-by: ckohen Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/rest/src/lib/REST.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/rest/src/lib/REST.ts b/packages/rest/src/lib/REST.ts index 3502b4a16ac9..d879ad6ea469 100644 --- a/packages/rest/src/lib/REST.ts +++ b/packages/rest/src/lib/REST.ts @@ -434,16 +434,20 @@ export class REST extends AsyncEventEmitter { }; } - const majorIdMatch = /^\/(?:channels|guilds|webhooks)\/(\d{17,19})/.exec(endpoint); + const majorIdMatch = /(?:^\/webhooks\/(\d{17,19}\/[^/?]+))|(?:^\/(?:channels|guilds|webhooks)\/(\d{17,19}))/.exec( + endpoint, + ); - // Get the major id for this route - global otherwise - const majorId = majorIdMatch?.[1] ?? 'global'; + // Get the major id or id + token for this route - global otherwise + const majorId = majorIdMatch?.[2] ?? majorIdMatch?.[1] ?? 'global'; const baseRoute = endpoint // Strip out all ids .replaceAll(/\d{17,19}/g, ':id') // Strip out reaction as they fall under the same bucket - .replace(/\/reactions\/(.*)/, '/reactions/:reaction'); + .replace(/\/reactions\/(.*)/, '/reactions/:reaction') + // Strip out webhook tokens + .replace(/\/webhooks\/:id\/[^/?]+/, '/webhooks/:id/:token'); let exceptions = '';