Skip to content

Commit

Permalink
Fallback to numeric timezone check
Browse files Browse the repository at this point in the history
Only few timezones have abbreviations. I found this bug, while testing
in my location, and since my timezone have no abbreviation, even if
date template tells use tz code, Go replaced it with number value (in
my case -5). Because of this all HMAC tests was failing on my machine.

Go date parsing mechanism do not support parsing timezone both with
numeric and abbreviation timezones, so we have to manually fallback to
it.
  • Loading branch information
buger committed Sep 29, 2017
1 parent 18abb70 commit 6a38e41
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mw_hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,15 @@ func (hm *HMACMiddleware) authorizationError(r *http.Request) (error, int) {

func (hm HMACMiddleware) checkClockSkew(dateHeaderValue string) bool {
// Reference layout for parsing time: "Mon Jan 2 15:04:05 MST 2006"

refDate := "Mon, 02 Jan 2006 15:04:05 MST"

// Fall back to a numeric timezone, since some environments don't provide a timezone name code
refDateNumeric := "Mon, 02 Jan 2006 15:04:05 -07"

tim, err := time.Parse(refDate, dateHeaderValue)
if err != nil {
tim, err = time.Parse(refDateNumeric, dateHeaderValue)
}

if err != nil {
log.WithFields(logrus.Fields{
Expand Down

0 comments on commit 6a38e41

Please sign in to comment.