Skip to content

Commit

Permalink
fix(file-log): reject file path that has leading/trailing space (#14141)
Browse files Browse the repository at this point in the history
  • Loading branch information
raoxiaoyan authored Jan 16, 2025
1 parent a6895f6 commit ce15c78
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**file-log**: Fixed an issue where an error would occur when there were spaces at the beginning or end of a path."
type: bugfix
scope: Plugin
2 changes: 1 addition & 1 deletion kong/plugins/file-log/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ return {
fields = {
{ path = { description = "The file path of the output log file. The plugin creates the log file if it doesn't exist yet.", type = "string",
required = true,
match = [[^[^*&%%\`]+$]],
match = [[^[^%s*&%%\`][^*&%%\`]*[^%s*&%%\`]$]],
err = "not a valid filename",
}, },
{ reopen = { description = "Determines whether the log file is closed and reopened on every request.", type = "boolean", required = true, default = false }, },
Expand Down
96 changes: 95 additions & 1 deletion spec/03-plugins/04-file-log/02-schema_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("Plugin: file-log (schema)", function()
},
----------------------------------------
{
name = "rejects invalid filename",
name = "rejects invalid filename includes *",
input = {
path = "/ovo*",
reopen = true
Expand All @@ -30,6 +30,100 @@ describe("Plugin: file-log (schema)", function()
}
},
----------------------------------------
{
name = "rejects invalid filename includes `",
input = {
path = "/ovo`",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "rejects invalid filename includes &",
input = {
path = "test&thing",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "rejects invalid filename includes %",
input = {
path = "test%thing",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "rejects invalid filename includes \\",
input = {
path = "test\\thing",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "beginning spaces are not allowed",
input = {
path = " /ovo",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
-- ----------------------------------------
{
name = "trailing spaces are not allowed",
input = {
path = "/ovo ",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "accept valid filename that includes space",
input = {
path = "/o vo.loga",
reopen = true
},
output = true,
error = nil,
},
------------------------------------
{
name = "accepts valid filename",
input = {
Expand Down

1 comment on commit ce15c78

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong-dev:ce15c785093bf822bd714775bef2f045592125e5
Artifacts available https://github.com/Kong/kong/actions/runs/12803306553

Please sign in to comment.