Skip to content

Conversation

@kamaln7
Copy link
Contributor

@kamaln7 kamaln7 commented Apr 7, 2023

This adds a webhook package to be used by DigitalOcean users directly and consulted as a reference implementation of the request signing spec.

Example usage:

http.HandleFunc("/webhook", func(w http.ResponseWriter, req *http.Request) {
   // only allow POST requests
   if req.Method != http.MethodPost {
       w.WriteHeader(http.StatusMethodNotAllowed)
       return
   }


   // verify request authenticity
   err := webhook.VerifyHTTPRequest(req, "webhook-secret", webhook.VerificationOpts{})
   if err != nil {
       w.WriteHeader(http.StatusForbidden)
       w.Write([]byte(err.Error()))
       return
   }


   // read the request body
   eventJSON, err := io.ReadAll(req.Body)
   if err != nil {
       w.WriteHeader(http.StatusInternalServerError)
       w.Write([]byte(err.Error()))
       return
   }
   defer req.Body.Close()
  
   eventName := req.Header.Get(webhook.HTTPHeaderEventName)
   // parse the request body json into a structured type using the eventName to determine
   // which type of event it is
   // ...
})

Copy link
Member

@andrewsomething andrewsomething left a comment

Choose a reason for hiding this comment

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

For posterity, I wanted to carry over my comment from a discussion of this elsewhere. It would be great to have some package level comments that discuss the signature format and perhaps include the example from the PR description.

@gitguardian
Copy link

gitguardian bot commented Nov 25, 2024

⚠️ GitGuardian has uncovered 4 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard.
Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9440723 Triggered PostgreSQL Credentials aca056d databases_test.go View secret
9440723 Triggered PostgreSQL Credentials aca056d databases_test.go View secret
9440724 Triggered PostgreSQL Credentials aca056d databases_test.go View secret
9440724 Triggered PostgreSQL Credentials aca056d databases_test.go View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants