Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(REST): strip webhook tokens #9723

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
D4isDAVID marked this conversation as resolved.
Show resolved Hide resolved
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?.[1] ?? majorIdMatch?.[2] ?? 'global';
D4isDAVID marked this conversation as resolved.
Show resolved Hide resolved

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');
D4isDAVID marked this conversation as resolved.
Show resolved Hide resolved

let exceptions = '';

Expand Down