Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: informative error message for invalid jwk #9904

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
- **Zipkin**: Fix an issue where the global plugin's sample ratio overrides route-specific.
[#9877](https://github.com/Kong/kong/pull/9877)

#### Core

- Improve error message for invalid jwk entries



## 3.1.0 (Unreleased)

Expand Down
2 changes: 1 addition & 1 deletion kong/db/schema/entities/keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ return {
-- running customer_validator
local ok, val_err = typedefs.jwk.custom_validator(entity.jwk)
if not ok or val_err then
return nil, "could not load JWK"
return nil, val_err or "could not load JWK"
end
-- FIXME: this does not execute the `custom_validator` part.
-- how to do that without loading that manually as seen above
Expand Down
2 changes: 1 addition & 1 deletion kong/db/schema/typedefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ local function validate_jwk(key)

local pk, err = openssl_pkey.new(key, { format = "JWK" })
if not pk or err then
return false, "could not load JWK" .. (err or "")
return false, "could not load JWK, likely not a valid key"
end
return true
end
Expand Down
14 changes: 14 additions & 0 deletions spec/02-integration/04-admin_api/21-admin-api-keys_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ for _, strategy in helpers.all_strategies() do
local key_body = assert.res_status(201, j_key)
test_jwk_key = cjson.decode(key_body)
end)

it("create invalid JWK", function()
local j_key = helpers.admin_client():post("/keys", {
headers = HEADERS,
body = {
name = "jwk invalid",
jwk = '{"kid": "36"}',
kid = "36"
}
})
local key_body = assert.res_status(400, j_key)
local jwk_key = cjson.decode(key_body)
assert.equal('schema violation (could not load JWK, likely not a valid key)', jwk_key.message)
end)
end)


Expand Down