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(utils) accept hosts ending in dots #6864

Merged
merged 1 commit into from
Mar 16, 2021
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
2 changes: 1 addition & 1 deletion kong-2.3.3-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = {
"luasyslog == 1.0.0",
"kikito/sandbox == 1.0.1",
"lua_pack == 1.0.5",
"lua-resty-dns-client == 5.2.1",
"lua-resty-dns-client == 5.2.2",
"lua-resty-worker-events == 1.0.0",
"lua-resty-healthcheck == 1.4.1",
"lua-resty-cookie == 0.1.0",
Expand Down
9 changes: 6 additions & 3 deletions kong/tools/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -942,9 +942,12 @@ _M.check_hostname = function(address)
end

-- Reject prefix/trailing dashes and dots in each segment
-- note: punycode allowes prefixed dash, if the characters before the dash are escaped
for _, segment in ipairs(split(name, ".")) do
if segment == "" or segment:match("-$") or segment:match("^%.") or segment:match("%.$") then
-- notes:
-- - punycode allows prefixed dash, if the characters before the dash are escaped
-- - FQDN can end in dots
for index, segment in ipairs(split(name, ".")) do
if segment:match("-$") or segment:match("^%.") or segment:match("%.$") or
(segment == "" and index ~= #split(name, ".")) then
return nil, "invalid hostname: " .. address
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/01-unit/01-db/01-schema/05-services_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ describe("services", function()
local invalid_hosts = {
"/example",
".example",
"example.",
"example:",
"mock;bin",
"example.com/org",
Expand Down Expand Up @@ -388,6 +387,7 @@ describe("services", function()
"hello.abcd",
"example_api.com",
"localhost",
"example.test.",
-- below:
-- punycode examples from RFC3492;
-- https://tools.ietf.org/html/rfc3492#page-14
Expand Down
1 change: 0 additions & 1 deletion spec/01-unit/01-db/01-schema/06-routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ describe("routes schema", function()
local invalid_hosts = {
"/example",
".example",
"example.",
"example:",
"mock;bin",
"example.com/org",
Expand Down
2 changes: 1 addition & 1 deletion spec/01-unit/01-db/01-schema/09-upstreams_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ describe("load upstreams", function()
{{ active = { https_sni = "127.0.0.1:8080", }}, invalid_ip },
{{ active = { https_sni = "/example", }}, invalid_host },
{{ active = { https_sni = ".example", }}, invalid_host },
{{ active = { https_sni = "example.", }}, invalid_host },
{{ active = { https_sni = "example:", }}, invalid_host },
{{ active = { https_sni = "mock;bin", }}, invalid_host },
{{ active = { https_sni = "example.com/org", }}, invalid_host },
Expand Down Expand Up @@ -392,6 +391,7 @@ describe("load upstreams", function()
{ active = { http_path = "/" }},
{ active = { http_path = "/test" }},
{ active = { https_sni = "example.com" }},
{ active = { https_sni = "example.test.", }},
{ active = { https_verify_certificate = false }},
{ active = { healthy = { interval = 0 }}},
{ active = { healthy = { http_statuses = { 200, 300 } }}},
Expand Down
4 changes: 2 additions & 2 deletions spec/01-unit/05-utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,14 @@ describe("Utils", function()
it("validates hostnames", function()
local valids = {"hello.com", "hello.fr", "test.hello.com", "1991.io", "hello.COM",
"HELLO.com", "123helloWORLD.com", "example.123", "example-api.com",
"hello.abcd", "example_api.com", "localhost",
"hello.abcd", "example_api.com", "localhost", "example.",
-- punycode examples from RFC3492; https://tools.ietf.org/html/rfc3492#page-14
-- specifically the japanese ones as they mix ascii with escaped characters
"3B-ww4c5e180e575a65lsy2b", "-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n",
"Hello-Another-Way--fc4qua05auwb3674vfr0b", "2-u9tlzr9756bt3uc0v",
"MajiKoi5-783gue6qz075azm5e", "de-jg4avhby1noc0d", "d9juau41awczczp",
}
local invalids = {"/example", ".example", "example.", "exam;ple",
local invalids = {"/example", ".example", "exam;ple",
"example.com/org",
"example-.org", "example.org-",
"hello..example.com", "hello-.example.com",
Expand Down