Skip to content

fix(webhook): return 401 when signature header is missing#4278

Merged
Siumauricio merged 4 commits intoDokploy:canaryfrom
mixelburg:fix/webhook-401-missing-signature
Apr 29, 2026
Merged

fix(webhook): return 401 when signature header is missing#4278
Siumauricio merged 4 commits intoDokploy:canaryfrom
mixelburg:fix/webhook-401-missing-signature

Conversation

@mixelburg
Copy link
Copy Markdown
Contributor

@mixelburg mixelburg commented Apr 21, 2026

Fixes #4275

When the signature header is absent, webhooks.verify() receives undefined and throws, causing a 500. Now we check for the header early and return 401 with a clear message.

Greptile Summary

Adds an early !signature guard to return 401 when the x-hub-signature-256 header is absent, fixing the 500 thrown by webhooks.verify(body, undefined). Also removes the as string type cast at the verify call site.

Confidence Score: 5/5

Safe to merge; the core fix is correct and the remaining note is minor.

The 401 early-return for a missing signature is clearly correct and consistent with the existing 401 for a bad signature. The only concern (handling string[] header values) is pre-existing behaviour that was previously hidden by the as string cast, and GitHub realistically never sends multiple signature headers.

No files require special attention.

Reviews (1): Last reviewed commit: "[autofix.ci] apply automated fixes" | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

@mixelburg mixelburg requested a review from Siumauricio as a code owner April 21, 2026 22:04
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 21, 2026
@dosubot dosubot Bot added bug Something isn't working size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Apr 21, 2026
Comment on lines 26 to +30
const signature = req.headers["x-hub-signature-256"];
if (!signature) {
res.status(401).json({ message: "Missing signature header" });
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 string[] case unhandled after removing the cast

After the if (!signature) guard, TypeScript narrows signature to string | string[] — a non-empty array is truthy and passes the check. webhooks.verify expects a string, so if a request arrives with multiple x-hub-signature-256 headers (or TypeScript strict mode is enabled) this could cause a compilation error or a runtime failure. The previous as string cast silently suppressed this, but removing it without handling the array case may break the build.

Consider extracting a definite string value:

Suggested change
const signature = req.headers["x-hub-signature-256"];
if (!signature) {
res.status(401).json({ message: "Missing signature header" });
return;
}
const rawSig = req.headers["x-hub-signature-256"];
const signature = Array.isArray(rawSig) ? rawSig[0] : rawSig;
if (!signature) {
res.status(401).json({ message: "Missing signature header" });
return;
}

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Apr 22, 2026
@Siumauricio Siumauricio merged commit 0e5fc58 into Dokploy:canary Apr 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webhook endpoint returns 500 instead of 401 when X-Hub-Signature-256 header is missing

2 participants