Nginx read secret and webhook headers

Viewed 324

A Webhook from Github is passing through Nginx proxy.

The webhook uses secret and the header is sent as X-Hub-Signature-256.

I want to make Nginx filtering requests, i.e I need Nginx to take the webhook header value and compare it to $SECRET_TOKEN. If the secret is right, it will send 200 and If not, 403.

I thought of something like this, but could find a way to implement it:

server {
  listen 80;
  server_name _;

  location /payload {
      
      #Read the header sent by the webhook (header name: X-Hub-Signature-256)
      #If the header content matches $SECRET_TOKEN I defined on Nginx then return 200
      #Else, return 403 
  }
}

Please help with implementing this pseudo as I couldn't find any example online.

Thanks in advance.

0 Answers
Related