Skip to content

Commit 9b47502

Browse files
author
Gustavo Oliveira
committed
fixes #537: Incorrect Handling of Bearer Token with trailing space in openidc_get_bearer_access_token
1 parent 9e37848 commit 9b47502

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/resty/openidc.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ local function get_first_header_and_strip_whitespace(headers, header_name)
222222
return header and header:gsub('%s', '')
223223
end
224224

225+
local function trim(s)
226+
if s then
227+
return s:match("^%s*(.-)%s*$")
228+
end
229+
return s
230+
end
231+
225232
local function get_forwarded_parameter(headers, param_name)
226233
local forwarded = get_first_header(headers, 'Forwarded')
227234
local params = {}
@@ -1701,7 +1708,7 @@ local function openidc_get_bearer_access_token(opts)
17011708
-- get the access token from the Authorization header
17021709
local headers = ngx.req.get_headers()
17031710
local header_name = opts.auth_accept_token_as_header_name or "Authorization"
1704-
local header = get_first(headers[header_name])
1711+
local header = trim(get_first(headers[header_name]))
17051712

17061713
if header == nil then
17071714
err = "no Authorization header found"

0 commit comments

Comments
 (0)