Skip to content

Commit

Permalink
fix(REST): strip webhook tokens (#9723)
Browse files Browse the repository at this point in the history
* fix(REST): strip webhook tokens

* fix(REST): implement requested changes

Co-authored-by: ckohen <chaikohen@gmail.com>

---------

Co-authored-by: ckohen <chaikohen@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 11, 2023
1 parent 2a25eea commit cf49f40
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/rest/src/lib/REST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,20 @@ export class REST extends AsyncEventEmitter<RestEventsMap> {
};
}

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 = '';

Expand Down

0 comments on commit cf49f40

Please sign in to comment.