Merge pull request #965 from harshavardhana/handle-spaces

signature: Handle all corner cases with spaces.
master
Harshavardhana 9 years ago
commit ae52fc682d
  1. 18
      api-signature.go

@ -40,18 +40,20 @@ func getCredentialsFromAuth(authValue string) ([]string, *probe.Error) {
if authValue == "" { if authValue == "" {
return nil, probe.NewError(errMissingAuthHeaderValue) return nil, probe.NewError(errMissingAuthHeaderValue)
} }
authFields := strings.Split(strings.TrimSpace(authValue), ",") // replace all spaced strings
if len(authFields) != 3 { authValue = strings.Replace(authValue, " ", "", -1)
return nil, probe.NewError(errInvalidAuthHeaderValue) if !strings.HasPrefix(authValue, authHeaderPrefix) {
}
authPrefixFields := strings.Fields(authFields[0])
if len(authPrefixFields) != 2 {
return nil, probe.NewError(errMissingFieldsAuthHeader) return nil, probe.NewError(errMissingFieldsAuthHeader)
} }
if authPrefixFields[0] != authHeaderPrefix { if !strings.HasPrefix(strings.TrimPrefix(authValue, authHeaderPrefix), "Credential") {
return nil, probe.NewError(errInvalidAuthHeaderPrefix) return nil, probe.NewError(errInvalidAuthHeaderPrefix)
} }
credentials := strings.Split(strings.TrimSpace(authPrefixFields[1]), "=") authValue = strings.TrimPrefix(authValue, authHeaderPrefix)
authFields := strings.Split(strings.TrimSpace(authValue), ",")
if len(authFields) != 3 {
return nil, probe.NewError(errInvalidAuthHeaderValue)
}
credentials := strings.Split(strings.TrimSpace(authFields[0]), "=")
if len(credentials) != 2 { if len(credentials) != 2 {
return nil, probe.NewError(errMissingFieldsCredentialTag) return nil, probe.NewError(errMissingFieldsCredentialTag)
} }

Loading…
Cancel
Save