Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
fix param extraction in keyFromParam
Browse files Browse the repository at this point in the history
  • Loading branch information
DavZim committed Dec 23, 2022
1 parent 279f4b7 commit b759180
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package keyauth

import (
"errors"
"net/url"
"strings"

"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -165,8 +166,14 @@ func keyFromForm(param string) func(c *fiber.Ctx) (string, error) {
// keyFromParam returns a function that extracts api key from the url param string.
func keyFromParam(param string) func(c *fiber.Ctx) (string, error) {
return func(c *fiber.Ctx) (string, error) {
key := c.Params(param)
if key == "" {
// somehow two path unescapes are needed to get the original key again
// see also tests for param in main_test.go
key, err := url.PathUnescape(c.Params(param))
if err != nil {
return "", ErrMissingOrMalformedAPIKey
}
key, err = url.PathUnescape(key)
if key == "" || err != nil {
return "", ErrMissingOrMalformedAPIKey
}
return key, nil
Expand Down

0 comments on commit b759180

Please sign in to comment.