Skip to content

Commit fabf64e

Browse files
authored
Merge pull request #538 from gustoliv/master
Incorrect Handling of Bearer Token with trailing space in openidc_get_bearer_access_token
2 parents d181a80 + 18ffe28 commit fabf64e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/resty/openidc.lua

Lines changed: 9 additions & 2 deletions
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"
@@ -1717,7 +1724,7 @@ local function openidc_get_bearer_access_token(opts)
17171724
end
17181725

17191726
local access_token = header:sub(divider + 1)
1720-
if access_token == nil then
1727+
if access_token == "" then
17211728
err = "no Bearer access token value found"
17221729
log(ERROR, err)
17231730
return nil, err

0 commit comments

Comments
 (0)