-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(key-auth) validate the configured headernames
Adds validation of header names (was completely absent) due to nginx/openresty config the '_' is also considered an invalid character. Fix Kong#2013 Signed-off-by: Thibault Charbonnier <[email protected]>
- Loading branch information
1 parent
1932b63
commit 73437ef
Showing
4 changed files
with
122 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,52 @@ | ||
local utils = require "kong.tools.utils" | ||
|
||
|
||
local function check_user(anonymous) | ||
if anonymous == "" or utils.is_valid_uuid(anonymous) then | ||
return true | ||
end | ||
|
||
return false, "the anonymous user must be empty or a valid uuid" | ||
end | ||
|
||
|
||
local function check_keys(keys) | ||
for _, key in ipairs(keys) do | ||
local res, err = utils.validate_header_name(key, false) | ||
|
||
if not res then | ||
return false, "'" .. key .. "' is illegal: " .. err | ||
end | ||
end | ||
|
||
return true | ||
end | ||
|
||
|
||
local function default_key_names(t) | ||
if not t.key_names then | ||
return {"apikey"} | ||
return { "apikey" } | ||
end | ||
end | ||
|
||
|
||
return { | ||
no_consumer = true, | ||
fields = { | ||
key_names = {required = true, type = "array", default = default_key_names}, | ||
hide_credentials = {type = "boolean", default = false}, | ||
anonymous = {type = "string", default = "", func = check_user}, | ||
key_names = { | ||
required = true, | ||
type = "array", | ||
default = default_key_names, | ||
func = check_keys, | ||
}, | ||
hide_credentials = { | ||
type = "boolean", | ||
default = false, | ||
}, | ||
anonymous = { | ||
type = "string", | ||
default = "", | ||
func = check_user, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters