mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 20:28:15 +03:00
Fix parsing of Authorization Bearer header (#3376)
The semantics of the Authorization header are defined by RFC 9110, which says: > It uses a case-insensitive token to identify the authentication scheme: Therefore, "bearer", "Bearer", and "bEARER" are equivalent. This patch fixes the parsing of the Authorization header to check for the Bearer authentication scheme case insensitively. I've modified one of the test cases to use lowercase "bearer", so there's test coverage for this.
This commit is contained in:
parent
6fc3fa37da
commit
092134f3f3
2 changed files with 7 additions and 4 deletions
|
@ -69,10 +69,13 @@ func RequireExternalAPIAccessToken(scope string, handler ExternalAccessTokenHand
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
authHeader := strings.Split(r.Header.Get("Authorization"), "Bearer ")
|
authHeader := r.Header.Get("Authorization")
|
||||||
token := strings.Join(authHeader, "")
|
token := ""
|
||||||
|
if strings.HasPrefix(strings.ToLower(authHeader), "bearer ") {
|
||||||
|
token = authHeader[len("bearer "):]
|
||||||
|
}
|
||||||
|
|
||||||
if len(authHeader) == 0 || token == "" {
|
if token == "" {
|
||||||
log.Warnln("invalid access token")
|
log.Warnln("invalid access token")
|
||||||
accessDenied(w)
|
accessDenied(w)
|
||||||
return
|
return
|
||||||
|
|
|
@ -83,7 +83,7 @@ test('send a system message using access token', async (done) => {
|
||||||
};
|
};
|
||||||
const res = await request
|
const res = await request
|
||||||
.post('/api/integrations/chat/system')
|
.post('/api/integrations/chat/system')
|
||||||
.set('Authorization', 'Bearer ' + accessToken)
|
.set('Authorization', 'bearer ' + accessToken)
|
||||||
.send(payload)
|
.send(payload)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
done();
|
done();
|
||||||
|
|
Loading…
Reference in a new issue