Skip to content

Commit

Permalink
fix: trim and validate bearer token
Browse files Browse the repository at this point in the history
- trim and validate the bearer token properly

Signed-off-by: slimm609 <[email protected]>
  • Loading branch information
slimm609 committed Nov 17, 2023
1 parent 1c829a4 commit 02f6b5a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/request/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (h http) processBearerToken() (username string, groups []string, err error)
return "", nil, fmt.Errorf("cannot create TokenReview")
}

if !tr.Status.Authenticated {
return "", nil, fmt.Errorf("cannot verify the token due to error")
}

if statusErr := tr.Status.Error; len(statusErr) > 0 {
return "", nil, fmt.Errorf("cannot verify the token due to error")
}
Expand All @@ -122,7 +126,7 @@ func (h http) processBearerToken() (username string, groups []string, err error)
}

func (h http) bearerToken() string {
return strings.ReplaceAll(h.Header.Get("Authorization"), "Bearer ", "")
return strings.TrimSpace(strings.ReplaceAll(h.Header.Get("Authorization"), "Bearer ", ""))
}

type authenticationFn func() (username string, groups []string, err error)
Expand Down

0 comments on commit 02f6b5a

Please sign in to comment.