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

feat: strictly validate the input of core resources #10233

Merged
merged 1 commit into from
Sep 20, 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
19 changes: 16 additions & 3 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ local health_checker = {
{required = {"active"}},
{required = {"active", "passive"}},
},
additionalProperties = false,
}


Expand Down Expand Up @@ -501,7 +502,8 @@ local upstream_schema = {
oneOf = {
{required = {"nodes"}},
{required = {"service_name", "discovery_type"}},
}
},
additionalProperties = false
}

-- TODO: add more nginx variable support
Expand Down Expand Up @@ -662,6 +664,7 @@ _M.route = {
{required = {"script", "plugin_config_id"}},
}
},
additionalProperties = false,
}


Expand Down Expand Up @@ -689,6 +692,7 @@ _M.service = {
uniqueItems = true,
},
},
additionalProperties = false,
}


Expand All @@ -707,6 +711,7 @@ _M.consumer = {
desc = desc_def,
},
required = {"username"},
additionalProperties = false,
}


Expand Down Expand Up @@ -817,7 +822,8 @@ _M.ssl = {
{required = {"snis", "key", "cert"}}
}
},
["else"] = {required = {"key", "cert"}}
["else"] = {required = {"key", "cert"}},
additionalProperties = false,
}


Expand All @@ -834,6 +840,7 @@ _M.proto = {
}
},
required = {"content"},
additionalProperties = false,
}


Expand All @@ -846,6 +853,7 @@ _M.global_rule = {
update_time = timestamp_def
},
required = {"id", "plugins"},
additionalProperties = false,
}


Expand Down Expand Up @@ -879,6 +887,7 @@ local xrpc_protocol_schema = {
dependencies = {
name = {"conf"},
},
additionalProperties = false,
},
},

Expand Down Expand Up @@ -913,7 +922,8 @@ _M.stream_route = {
upstream_id = id_schema,
plugins = plugins_schema,
protocol = xrpc_protocol_schema,
}
},
additionalProperties = false,
}


Expand All @@ -929,6 +939,7 @@ _M.plugins = {
stream = {
type = "boolean"
},
additionalProperties = false,
},
required = {"name"}
}
Expand All @@ -946,6 +957,7 @@ _M.plugin_config = {
update_time = timestamp_def
},
required = {"id", "plugins"},
additionalProperties = false,
}


Expand All @@ -960,6 +972,7 @@ _M.consumer_group = {
update_time = timestamp_def
},
required = {"id", "plugins"},
additionalProperties = false,
}


Expand Down
7 changes: 4 additions & 3 deletions t/admin/upstream-array-nodes.t
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ no valid upstream node



=== TEST 9: additional properties is valid
=== TEST 9: additional properties is invalid
--- config
location /t {
content_by_lua_block {
Expand All @@ -277,8 +277,9 @@ no valid upstream node
}
--- request
GET /t
--- response_body
passed
--- error_code: 400
--- response_body eval
qr/\{"error_msg":"invalid configuration: additional properties forbidden, found .*"\}/



Expand Down
7 changes: 4 additions & 3 deletions t/admin/upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ GET /t



=== TEST 11: additional properties is valid
=== TEST 11: additional properties is invalid
--- config
location /t {
content_by_lua_block {
Expand All @@ -354,8 +354,9 @@ GET /t
}
--- request
GET /t
--- response_body
passed
--- error_code: 400
--- response_body eval
qr/\{"error_msg":"invalid configuration: additional properties forbidden, found .*"\}/



Expand Down
7 changes: 0 additions & 7 deletions t/wasm/global-rule.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ __DATA__
local code, body = t('/apisix/admin/global_rules/1',
ngx.HTTP_PUT,
[[{
"uri": "/hello",
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
},
Comment on lines -60 to -66
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you remove this?

Copy link
Contributor Author

@Sn0rt Sn0rt Sep 20, 2023

Choose a reason for hiding this comment

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

This field is not as expected and is not allowed to be passed into upstream in the global-rule.

_M.global_rule = {
    type = "object",
    properties = {
        id = id_schema,
        plugins = plugins_schema,
        create_time = timestamp_def,
        update_time = timestamp_def
    },
    required = {"id", "plugins"},
    additionalProperties = false,
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If you delete this block, the test case will fail

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have test this PR on myself repo https://github.com/Sn0rt/apisix/pull/9

"plugins": {
"wasm_log": {
"conf": "blahblah"
Expand Down