Skip to content

[BUG]: Signature not able to be validated in Next.js routes #1165

@declan-wade

Description

@declan-wade

What happened?

I am having a lot of difficulty getting the webhook signature to validate in the route.ts via the Next.js app router - it just fails every time despite the secret being correct and following the documentation example.

"use server";

import { Webhooks } from "@octokit/webhooks";

const webhooks = new Webhooks({
  secret: "abc",
});

export async function POST(request: Request) {
  try {

    const body = await request.text();
    const signature = request.headers.get("x-hub-signature-256");
   
    if (!signature) {
      return new Response("Missing signature", { status: 401 });
    }
    console.info(signature); // prints:  sha256=2867...... etc

    const isValid = await webhooks.verify(body, signature);
    console.info(isValid);

    if (!isValid) {
      console.log("Signature validation failed");
      return new Response("Invalid signature", { status: 401 });
    }

    console.log("Signature validation successful");
    // rest of code
}

isValid always returns false so the request results in 401 every time

I'm at a loss at what else to try... Happy to debug further if required.

Versions

@octokit/webhooks 14.1.1, next 15.2.4, Node v24.3.0, Bun 1.2.16

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working as documented, or is being fixed

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions