Coder Social home page Coder Social logo

Comments (4)

surprisetalk avatar surprisetalk commented on May 26, 2024 1

Alright, here's a working example of GitHub signature verification for Deno:

import { Buffer } from "https://deno.land/std/io/mod.ts";
import { timingSafeEqual } from "https://deno.land/std/node/crypto.ts";
import { hmac } from "https://deno.land/x/[email protected]/mod.ts";

const encoder = new TextEncoder()

const signature = req.headers.get(`x-hub-signature`) ?? ``;
const signatureBuffer = encoder.encode(signature);

const payload = await req.body({ type: `text` }).value;

const algorithm = signature.startsWith("sha256=") ? "sha256" : "sha1";

const verification = `${algorithm}=${hmac(algorithm, "helloworld", payload, "utf8", "hex")}`;
const verificationBuffer = encoder.encode(verification);

// constant time comparison to prevent timing attachs
// https://stackoverflow.com/a/31096242/206879
// https://en.wikipedia.org/wiki/Timing_attack
const matchesSignature = signatureBuffer.length === verificationBuffer.length
  && await timingSafeEqual(signatureBuffer, verificationBuffer);

from webhooks-methods.js.

roj1512 avatar roj1512 commented on May 26, 2024

I accidentally clicked on 'bug'. The bug label might not be accurate.

from webhooks-methods.js.

surprisetalk avatar surprisetalk commented on May 26, 2024

I'm experiencing the same problem with both X-Hub-Signature and X-Hub-Signature-256.

from webhooks-methods.js.

roj1512 avatar roj1512 commented on May 26, 2024

I already made it working with https://stackoverflow.com/a/71088170/10379728.

from webhooks-methods.js.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.