Skip to content

Commit d579cbf

Browse files
Potential fix for code scanning alert no. 19: Server-side request forgery
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 694125d commit d579cbf

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

app/api/admin/integrations/test/route.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,15 @@ async function testDiscord(webhookUrl: string, botToken?: string, serverId?: str
148148
return { ok: false, message: 'Webhook URL must be a valid Discord HTTPS URL' }
149149
}
150150

151-
const res = await fetch(parsed.toString(), { method: 'GET' })
151+
const match = parsed.pathname.match(/^\/api\/webhooks\/(\d+)\/([A-Za-z0-9._-]+)$/)
152+
if (!match) {
153+
return { ok: false, message: 'Webhook URL must match Discord webhook format' }
154+
}
155+
156+
const [, webhookId, webhookToken] = match
157+
const safeWebhookUrl = `https://${hostname}/api/webhooks/${webhookId}/${webhookToken}`
158+
159+
const res = await fetch(safeWebhookUrl, { method: 'GET' })
152160
if (res.status === 401) return { ok: false, message: 'Invalid webhook URL' }
153161
if (!res.ok) return { ok: false, message: `Discord webhook error (${res.status})` }
154162
return { ok: true, message: 'Discord webhook is valid' }

0 commit comments

Comments
 (0)