Skip to content

Commit a98f1ca

Browse files
authored
feat: strictly validate the input of core resources (#10233)
1 parent 57a7dcd commit a98f1ca

File tree

4 files changed

+24
-16
lines changed

4 files changed

+24
-16
lines changed

apisix/schema_def.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ local health_checker = {
283283
{required = {"active"}},
284284
{required = {"active", "passive"}},
285285
},
286+
additionalProperties = false,
286287
}
287288

288289

@@ -501,7 +502,8 @@ local upstream_schema = {
501502
oneOf = {
502503
{required = {"nodes"}},
503504
{required = {"service_name", "discovery_type"}},
504-
}
505+
},
506+
additionalProperties = false
505507
}
506508

507509
-- TODO: add more nginx variable support
@@ -662,6 +664,7 @@ _M.route = {
662664
{required = {"script", "plugin_config_id"}},
663665
}
664666
},
667+
additionalProperties = false,
665668
}
666669

667670

@@ -689,6 +692,7 @@ _M.service = {
689692
uniqueItems = true,
690693
},
691694
},
695+
additionalProperties = false,
692696
}
693697

694698

@@ -707,6 +711,7 @@ _M.consumer = {
707711
desc = desc_def,
708712
},
709713
required = {"username"},
714+
additionalProperties = false,
710715
}
711716

712717

@@ -817,7 +822,8 @@ _M.ssl = {
817822
{required = {"snis", "key", "cert"}}
818823
}
819824
},
820-
["else"] = {required = {"key", "cert"}}
825+
["else"] = {required = {"key", "cert"}},
826+
additionalProperties = false,
821827
}
822828

823829

@@ -834,6 +840,7 @@ _M.proto = {
834840
}
835841
},
836842
required = {"content"},
843+
additionalProperties = false,
837844
}
838845

839846

@@ -846,6 +853,7 @@ _M.global_rule = {
846853
update_time = timestamp_def
847854
},
848855
required = {"id", "plugins"},
856+
additionalProperties = false,
849857
}
850858

851859

@@ -879,6 +887,7 @@ local xrpc_protocol_schema = {
879887
dependencies = {
880888
name = {"conf"},
881889
},
890+
additionalProperties = false,
882891
},
883892
},
884893

@@ -913,7 +922,8 @@ _M.stream_route = {
913922
upstream_id = id_schema,
914923
plugins = plugins_schema,
915924
protocol = xrpc_protocol_schema,
916-
}
925+
},
926+
additionalProperties = false,
917927
}
918928

919929

@@ -929,6 +939,7 @@ _M.plugins = {
929939
stream = {
930940
type = "boolean"
931941
},
942+
additionalProperties = false,
932943
},
933944
required = {"name"}
934945
}
@@ -946,6 +957,7 @@ _M.plugin_config = {
946957
update_time = timestamp_def
947958
},
948959
required = {"id", "plugins"},
960+
additionalProperties = false,
949961
}
950962

951963

@@ -960,6 +972,7 @@ _M.consumer_group = {
960972
update_time = timestamp_def
961973
},
962974
required = {"id", "plugins"},
975+
additionalProperties = false,
963976
}
964977

965978

t/admin/upstream-array-nodes.t

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ no valid upstream node
251251

252252

253253

254-
=== TEST 9: additional properties is valid
254+
=== TEST 9: additional properties is invalid
255255
--- config
256256
location /t {
257257
content_by_lua_block {
@@ -277,8 +277,9 @@ no valid upstream node
277277
}
278278
--- request
279279
GET /t
280-
--- response_body
281-
passed
280+
--- error_code: 400
281+
--- response_body eval
282+
qr/\{"error_msg":"invalid configuration: additional properties forbidden, found .*"\}/
282283

283284

284285

t/admin/upstream.t

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ GET /t
330330

331331

332332

333-
=== TEST 11: additional properties is valid
333+
=== TEST 11: additional properties is invalid
334334
--- config
335335
location /t {
336336
content_by_lua_block {
@@ -354,8 +354,9 @@ GET /t
354354
}
355355
--- request
356356
GET /t
357-
--- response_body
358-
passed
357+
--- error_code: 400
358+
--- response_body eval
359+
qr/\{"error_msg":"invalid configuration: additional properties forbidden, found .*"\}/
359360

360361

361362

t/wasm/global-rule.t

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ __DATA__
5757
local code, body = t('/apisix/admin/global_rules/1',
5858
ngx.HTTP_PUT,
5959
[[{
60-
"uri": "/hello",
61-
"upstream": {
62-
"type": "roundrobin",
63-
"nodes": {
64-
"127.0.0.1:1980": 1
65-
}
66-
},
6760
"plugins": {
6861
"wasm_log": {
6962
"conf": "blahblah"

0 commit comments

Comments
 (0)