mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
fix(webhooks): update github webhook validation
This commit is contained in:
@@ -44,6 +44,7 @@ export const ShowGitProviders = () => {
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<div className="grid gap-4 sm:grid-cols-1 md:grid-cols-1">
|
||||
{data?.map((gitProvider, index) => {
|
||||
const isGithub = gitProvider.providerType === "github";
|
||||
const isGitlab = gitProvider.providerType === "gitlab";
|
||||
@@ -60,7 +61,7 @@ export const ShowGitProviders = () => {
|
||||
className="space-y-4"
|
||||
key={`${gitProvider.gitProviderId}-${index}`}
|
||||
>
|
||||
<Card className="flex sm:flex-row max-sm:gap-2 flex-col justify-between items-center p-4">
|
||||
<Card className="flex sm:flex-row max-sm:gap-2 flex-col justify-between items-center p-4 h-full">
|
||||
<div className="flex items-center space-x-4 w-full">
|
||||
{gitProvider.providerType === "github" && (
|
||||
<GithubIcon className="w-6 h-6" />
|
||||
@@ -139,5 +140,6 @@ export const ShowGitProviders = () => {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { findAdmin } from "@/server/api/services/admin";
|
||||
import { db } from "@/server/db";
|
||||
import { applications, compose } from "@/server/db/schema";
|
||||
import { applications, compose, githubProvider } from "@/server/db/schema";
|
||||
import type { DeploymentJob } from "@/server/queues/deployments-queue";
|
||||
import { myQueue } from "@/server/queues/queueSetup";
|
||||
import { Webhooks } from "@octokit/webhooks";
|
||||
@@ -19,18 +19,26 @@ export default async function handler(
|
||||
return;
|
||||
}
|
||||
|
||||
if (!admin.githubWebhookSecret) {
|
||||
res.status(200).json({ message: "Github Webhook Secret not set" });
|
||||
const signature = req.headers["x-hub-signature-256"];
|
||||
const github = req.body;
|
||||
|
||||
const githubResult = await db.query.githubProvider.findFirst({
|
||||
where: eq(githubProvider.githubInstallationId, github.installation.id),
|
||||
});
|
||||
|
||||
if (!githubResult) {
|
||||
res.status(400).json({ message: "Github Installation not found" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!githubResult.githubWebhookSecret) {
|
||||
res.status(400).json({ message: "Github Webhook Secret not set" });
|
||||
return;
|
||||
}
|
||||
const webhooks = new Webhooks({
|
||||
secret: admin.githubWebhookSecret,
|
||||
secret: githubResult.githubWebhookSecret,
|
||||
});
|
||||
|
||||
const signature = req.headers["x-hub-signature-256"];
|
||||
const github = req.body;
|
||||
|
||||
const verified = await webhooks.verify(
|
||||
JSON.stringify(github),
|
||||
signature as string,
|
||||
|
||||
Reference in New Issue
Block a user