Skip to content

Instantly share code, notes, and snippets.

@cynipe
Created February 25, 2015 03:30
Show Gist options
  • Save cynipe/df7cbb7665f51df3168a to your computer and use it in GitHub Desktop.
Save cynipe/df7cbb7665f51df3168a to your computer and use it in GitHub Desktop.
Securing Github Webhook Endpoint with Nginx + Lua
-- 多分こんな感じでできる
local x_hub_signature = ngx.hader['X_Hub_Signature']
local body = ngx.req.read_body
local expected_signature = 'sha1=' .. ngx.hmac_sha1(ngx.var.secret_token, body)
if expected_signature ~= x_hub_signature then
ngx.log(ngx.WARN, 'Invalid access detected')
ngx.header.content_type = 'text/plain'
ngx.status = ngx.HTTP_UNAUTHORIZED
ngx.print('401 Access Denied')
return
end
-- TODO execでいいのかしら?
ngx.exec('/jenkins')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment