Skip to content

Commit

Permalink
fix(security): escape path parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu committed Nov 21, 2024
1 parent 0095470 commit 1ba3472
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 0 deletions.
22 changes: 22 additions & 0 deletions deno/rest/v10/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,17 @@ export const Routes = {
},
};

for (const [key, fn] of Object.entries(Routes)) {
Routes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(Routes);

export const StickerPackApplicationId = '710982414301790216';

export enum ImageFormat {
Expand Down Expand Up @@ -1350,6 +1361,17 @@ export const CDNRoutes = {
},
};

for (const [key, fn] of Object.entries(CDNRoutes)) {
CDNRoutes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(CDNRoutes);

export type DefaultUserAvatarAssets = 0 | 1 | 2 | 3 | 4 | 5;

export type EmojiFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
Expand Down
11 changes: 11 additions & 0 deletions deno/rest/v6/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,14 @@ export const Routes = {
return `/oauth2/applications/@me`;
},
};

for (const [key, fn] of Object.entries(Routes)) {
Routes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(Routes);
11 changes: 11 additions & 0 deletions deno/rest/v8/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,17 @@ export const Routes = {
},
};

for (const [key, fn] of Object.entries(Routes)) {
Routes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(Routes);

export const RouteBases = {
api: `https://discord.com/api/v${APIVersion}`,
cdn: 'https://cdn.discordapp.com',
Expand Down
22 changes: 22 additions & 0 deletions deno/rest/v9/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,17 @@ export const Routes = {
},
};

for (const [key, fn] of Object.entries(Routes)) {
Routes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(Routes);

export const StickerPackApplicationId = '710982414301790216';

export enum ImageFormat {
Expand Down Expand Up @@ -1359,6 +1370,17 @@ export const CDNRoutes = {
},
};

for (const [key, fn] of Object.entries(CDNRoutes)) {
CDNRoutes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(CDNRoutes);

export type DefaultUserAvatarAssets = 0 | 1 | 2 | 3 | 4 | 5;

export type EmojiFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
Expand Down
22 changes: 22 additions & 0 deletions rest/v10/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,17 @@ export const Routes = {
},
};

for (const [key, fn] of Object.entries(Routes)) {
Routes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(Routes);

export const StickerPackApplicationId = '710982414301790216';

export enum ImageFormat {
Expand Down Expand Up @@ -1350,6 +1361,17 @@ export const CDNRoutes = {
},
};

for (const [key, fn] of Object.entries(CDNRoutes)) {
CDNRoutes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(CDNRoutes);

export type DefaultUserAvatarAssets = 0 | 1 | 2 | 3 | 4 | 5;

export type EmojiFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
Expand Down
11 changes: 11 additions & 0 deletions rest/v6/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,14 @@ export const Routes = {
return `/oauth2/applications/@me`;
},
};

for (const [key, fn] of Object.entries(Routes)) {
Routes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(Routes);
11 changes: 11 additions & 0 deletions rest/v8/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,17 @@ export const Routes = {
},
};

for (const [key, fn] of Object.entries(Routes)) {
Routes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(Routes);

export const RouteBases = {
api: `https://discord.com/api/v${APIVersion}`,
cdn: 'https://cdn.discordapp.com',
Expand Down
22 changes: 22 additions & 0 deletions rest/v9/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,17 @@ export const Routes = {
},
};

for (const [key, fn] of Object.entries(Routes)) {
Routes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(Routes);

export const StickerPackApplicationId = '710982414301790216';

export enum ImageFormat {
Expand Down Expand Up @@ -1359,6 +1370,17 @@ export const CDNRoutes = {
},
};

for (const [key, fn] of Object.entries(CDNRoutes)) {
CDNRoutes[key] = (...args: string[]) => {
const escaped = args.map((arg) => encodeURIComponent(arg));
// eslint-disable-next-line no-useless-call
return fn.call(null, ...escaped);
};
}

// Freeze the object so it can't be changed
Object.freeze(CDNRoutes);

export type DefaultUserAvatarAssets = 0 | 1 | 2 | 3 | 4 | 5;

export type EmojiFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
Expand Down

0 comments on commit 1ba3472

Please sign in to comment.