Skip to content

Commit

Permalink
bugfix: hide ssl private key in admin API. (apache#1240)
Browse files Browse the repository at this point in the history
  • Loading branch information
moonming authored and SaberMaster committed Jun 30, 2020
1 parent d4248cf commit 2a4ead7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lua/apisix/admin/ssl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ function _M.get(id)
return 500, {error_msg = err}
end

-- not return private key for security
if res.body and res.body.node and res.body.node.value then
res.body.node.value.key = nil
end

return res.status, res.body
end

Expand Down
4 changes: 3 additions & 1 deletion t/admin/ssl.t
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ passed
[[{
"node": {
"value": {
"sni": "test.com"
"sni": "test.com",
"key": null
},

"key": "/apisix/ssl/1"
},
"action": "get"
Expand Down
6 changes: 4 additions & 2 deletions t/lib/test_admin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ local function com_tab(pattern, data, deep)
for k, v in pairs(pattern) do
dir_names[deep] = k

if v == ngx.null then
v = nil
end

if type(v) == "table" then
local ok, err = com_tab(v, data[k], deep + 1)
if not ok then
Expand Down Expand Up @@ -135,12 +139,10 @@ function _M.test(uri, method, body, pattern)
if pattern == nil then
return res.status, "passed", res.body
end

local res_data = json.decode(res.body)
if type(pattern) == "string" then
pattern = json.decode(pattern)
end

local ok, err = com_tab(pattern, res_data)
if not ok then
return 500, "failed, " .. err, res_data
Expand Down

0 comments on commit 2a4ead7

Please sign in to comment.