diff --git a/assets/openapi.json b/assets/openapi.json
index ba11b111..e8acfd44 100644
--- a/assets/openapi.json
+++ b/assets/openapi.json
@@ -14981,7 +14981,289 @@
]
}
},
- "/webhooks/{webhook_id}/{token}/": {
+ "/webhooks/{webhook_id}/{webhook_token}/messages/{message_id}/": {
+ "patch": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "requestBody": {
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/MessageEditSchema"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Message"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/APIErrorResponse"
+ }
+ }
+ }
+ },
+ "403": {
+ "description": "No description available"
+ },
+ "404": {
+ "description": "No description available"
+ }
+ },
+ "parameters": [
+ {
+ "name": "webhook_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "webhook_id"
+ },
+ {
+ "name": "webhook_token",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "webhook_token"
+ },
+ {
+ "name": "message_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "message_id"
+ }
+ ],
+ "tags": [
+ "webhooks"
+ ]
+ },
+ "put": {
+ "x-right-required": "SEND_BACKDATED_EVENTS",
+ "x-permission-required": "SEND_MESSAGES",
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "requestBody": {
+ "required": true,
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/MessageCreateSchema"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Message"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/APIErrorResponse"
+ }
+ }
+ }
+ },
+ "403": {
+ "description": "No description available"
+ },
+ "404": {
+ "description": "No description available"
+ }
+ },
+ "parameters": [
+ {
+ "name": "webhook_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "webhook_id"
+ },
+ {
+ "name": "webhook_token",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "webhook_token"
+ },
+ {
+ "name": "message_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "message_id"
+ }
+ ],
+ "tags": [
+ "webhooks"
+ ]
+ },
+ "get": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/Message"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/APIErrorResponse"
+ }
+ }
+ }
+ },
+ "403": {
+ "description": "No description available"
+ },
+ "404": {
+ "description": "No description available"
+ }
+ },
+ "parameters": [
+ {
+ "name": "webhook_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "webhook_id"
+ },
+ {
+ "name": "webhook_token",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "webhook_token"
+ },
+ {
+ "name": "message_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "message_id"
+ }
+ ],
+ "tags": [
+ "webhooks"
+ ]
+ },
+ "delete": {
+ "security": [
+ {
+ "bearer": []
+ }
+ ],
+ "responses": {
+ "204": {
+ "description": "No description available"
+ },
+ "400": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/APIErrorResponse"
+ }
+ }
+ }
+ },
+ "404": {
+ "description": "No description available"
+ }
+ },
+ "parameters": [
+ {
+ "name": "webhook_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "webhook_id"
+ },
+ {
+ "name": "webhook_token",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "webhook_token"
+ },
+ {
+ "name": "message_id",
+ "in": "path",
+ "required": true,
+ "schema": {
+ "type": "string"
+ },
+ "description": "message_id"
+ }
+ ],
+ "tags": [
+ "webhooks"
+ ]
+ }
+ },
+ "/webhooks/{webhook_id}/{webhook_token}/": {
"get": {
"security": [
{
@@ -15015,13 +15297,13 @@
"description": "webhook_id"
},
{
- "name": "token",
+ "name": "webhook_token",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
- "description": "token"
+ "description": "webhook_token"
}
],
"tags": [
@@ -15073,13 +15355,13 @@
"description": "webhook_id"
},
{
- "name": "token",
+ "name": "webhook_token",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
- "description": "token"
+ "description": "webhook_token"
},
{
"name": "wait",
@@ -15139,13 +15421,13 @@
"description": "webhook_id"
},
{
- "name": "token",
+ "name": "webhook_token",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
- "description": "token"
+ "description": "webhook_token"
}
],
"tags": [
@@ -15207,13 +15489,13 @@
"description": "webhook_id"
},
{
- "name": "token",
+ "name": "webhook_token",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
- "description": "token"
+ "description": "webhook_token"
}
],
"tags": [
@@ -15221,7 +15503,7 @@
]
}
},
- "/webhooks/{webhook_id}/{token}/github/": {
+ "/webhooks/{webhook_id}/{webhook_token}/github/": {
"post": {
"security": [
{
@@ -15267,13 +15549,13 @@
"description": "webhook_id"
},
{
- "name": "token",
+ "name": "webhook_token",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
- "description": "token"
+ "description": "webhook_token"
},
{
"name": "wait",
diff --git a/src/api/routes/webhooks/#webhook_id/#token/github.ts b/src/api/routes/webhooks/#webhook_id/#webhook_token/github.ts
index 140d3618..140d3618 100644
--- a/src/api/routes/webhooks/#webhook_id/#token/github.ts
+++ b/src/api/routes/webhooks/#webhook_id/#webhook_token/github.ts
diff --git a/src/api/routes/webhooks/#webhook_id/#token/index.ts b/src/api/routes/webhooks/#webhook_id/#webhook_token/index.ts
index a832c8a2..886236ea 100644
--- a/src/api/routes/webhooks/#webhook_id/#token/index.ts
+++ b/src/api/routes/webhooks/#webhook_id/#webhook_token/index.ts
@@ -24,7 +24,6 @@ import { Webhook, Message } from "@spacebar/database";
import { Config, DiscordApiErrors, emitEvent, handleFile, ValidateName, WebhooksUpdateEvent } from "@spacebar/util";
import { executeWebhook } from "@spacebar/api/util/handlers/Webhook";
import { WebhookUpdateSchema } from "@spacebar/schemas";
-import { FindOptionsWhere } from "typeorm";
const router = Router({ mergeParams: true });
@@ -40,7 +39,7 @@ router.get(
},
}),
async (req: Request, res: Response) => {
- const { webhook_id, token } = req.params as { [key: string]: string };
+ const { webhook_id, webhook_token } = req.params as { [key: string]: string };
const webhook = await Webhook.findOne({
where: {
id: webhook_id,
@@ -52,7 +51,7 @@ router.get(
throw DiscordApiErrors.UNKNOWN_WEBHOOK;
}
- if (webhook.token !== token) {
+ if (webhook.token !== webhook_token) {
throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED;
}
@@ -123,7 +122,7 @@ router.delete(
},
}),
async (req: Request, res: Response) => {
- const { webhook_id, token } = req.params as { [key: string]: string };
+ const { webhook_id, webhook_token } = req.params as { [key: string]: string };
const webhook = await Webhook.findOne({
where: {
@@ -132,13 +131,9 @@ router.delete(
relations: { channel: true, guild: true, application: true },
});
- if (!webhook) {
- throw DiscordApiErrors.UNKNOWN_WEBHOOK;
- }
+ if (!webhook) throw DiscordApiErrors.UNKNOWN_WEBHOOK;
+ if (webhook.token !== webhook_token) throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED;
- if (webhook.token !== token) {
- throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED;
- }
const channel_id = webhook.channel_id;
await Message.delete({ channel_id, webhook_id });
await Webhook.delete({ id: webhook_id });
@@ -172,14 +167,17 @@ router.patch(
},
}),
async (req: Request, res: Response) => {
- // noinspection JSUnusedLocalSymbols - TODO: shouldnt token be checked?
- const { webhook_id, token } = req.params as { [key: string]: string };
+ const { webhook_id, webhook_token } = req.params as { [key: string]: string };
const body = req.body as WebhookUpdateSchema;
- const webhook = await Webhook.findOneOrFail({
+ const webhook = await Webhook.findOne({
where: { id: webhook_id },
relations: { user: true, channel: true, source_channel: true, guild: true, source_guild: true, application: true },
});
+
+ if (!webhook) throw DiscordApiErrors.UNKNOWN_WEBHOOK;
+ if (webhook.token != webhook_token) throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED;
+
const channel_id = webhook.channel_id;
if (!body.name && !body.avatar) {
throw new HTTPError("Empty webhook updates are not allowed", 50006);
diff --git a/src/api/util/handlers/Webhook.ts b/src/api/util/handlers/Webhook.ts
index 1f4f60a7..3e1114ab 100644
--- a/src/api/util/handlers/Webhook.ts
+++ b/src/api/util/handlers/Webhook.ts
@@ -28,7 +28,7 @@ export const executeWebhook = async (req: Request, res: Response) => {
const body = req.body as WebhookExecuteSchema;
const messageId = Snowflake.generate();
- const { webhook_id, token } = req.params as { [key: string]: string };
+ const { webhook_id, webhook_token } = req.params as { [key: string]: string };
const webhook = await Webhook.findOne({
where: {
@@ -37,13 +37,8 @@ export const executeWebhook = async (req: Request, res: Response) => {
relations: { channel: true, guild: true, application: true },
});
- if (!webhook) {
- throw DiscordApiErrors.UNKNOWN_WEBHOOK;
- }
-
- if (webhook.token !== token) {
- throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED;
- }
+ if (!webhook) throw DiscordApiErrors.UNKNOWN_WEBHOOK;
+ if (webhook.token !== webhook_token) throw DiscordApiErrors.INVALID_WEBHOOK_TOKEN_PROVIDED;
if (body.username) {
ValidateName(body.username);
|