Skip to content

Commit a95ab3a

Browse files
authored
Merge pull request #1507 from tkan145/backport-THREESCALE-11435-2.15
[THREESCALE-11435] Check for nil value when decode based64 value
2 parents 0eb5ecb + d3b7604 commit a95ab3a

File tree

4 files changed

+537
-1
lines changed

4 files changed

+537
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
5555

5656
- Fixed APIcast send request through proxy server even when `NO_PROXY` is used [PR #1478](https://github.com/3scale/APIcast/pull/1478) [THREESCALE-11128](https://issues.redhat.com/browse/THREESCALE-11128)
5757

58+
- Fixed APIcast panic when parsing invalid base64 encoded value [PR #1505](https://github.com/3scale/APIcast/pull/1505) [THEESCALE-11435](https://issues.redhat.com/browse/THREESCALE-11435)
59+
5860
### Added
5961

6062
- Detect number of CPU shares when running on Cgroups V2 [PR #1410](https://github.com/3scale/apicast/pull/1410) [THREESCALE-10167](https://issues.redhat.com/browse/THREESCALE-10167)

gateway/src/resty/http_authorization.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ local _M = {
99
local mt = { __index = _M }
1010

1111
function _M.parsers.Basic(param)
12+
local userid, password
1213
local user_pass = ngx.decode_base64(param)
13-
local userid, password = match(user_pass, '^(.*):(.*)$')
14+
if user_pass then
15+
userid, password = match(user_pass, '^(.*):(.*)$')
16+
end
1417

1518
return {
1619
userid = userid,

spec/resty/http_authorization_spec.lua

+7
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ describe('HTTP Authorization', function()
6060
assert.equal('', auth.userid)
6161
assert.equal('pass', auth.password)
6262
end)
63+
64+
it('do not panic with invalid header', function()
65+
local auth = authorization.new('Basic !123!')
66+
67+
assert.equal(nil, auth.userid)
68+
assert.equal(nil, auth.password)
69+
end)
6370
end)
6471

6572
describe('Bearer', function()

0 commit comments

Comments
 (0)