Skip to content

Commit 9eb9081

Browse files
Foo BarCopilot
andcommitted
fix(acl): validate external_user_label_field JSONPath syntax in check_schema
Invalid JSONPath expressions are now rejected at config time via jp.parse(). This prevents misconfigured routes from silently allowing all requests through when using deny-only ACL policies. Add TEST 53: schema rejects invalid JSONPath in external_user_label_field. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a94c471 commit 9eb9081

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

apisix/plugins/acl.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ function _M.check_schema(conf)
206206
if not ok then
207207
return false, err
208208
end
209+
210+
local _, parse_err = jp.parse(conf.external_user_label_field)
211+
if parse_err then
212+
return false, "invalid external_user_label_field: " .. parse_err
213+
end
214+
209215
return true
210216
end
211217

t/plugin/acl.t

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,48 @@ GET /t
14451445
14461446
14471447
1448-
=== TEST 53: delete route
1448+
=== TEST 53: TEST SCHEMA: invalid external_user_label_field (invalid JSONPath syntax)
1449+
--- config
1450+
location /t {
1451+
content_by_lua_block {
1452+
local t = require("lib.test_admin").test
1453+
local code, body = t('/apisix/admin/routes/1',
1454+
ngx.HTTP_PUT,
1455+
[[{
1456+
"uri": "/hello",
1457+
"upstream": {
1458+
"type": "roundrobin",
1459+
"nodes": {
1460+
"127.0.0.1:1980": 1
1461+
}
1462+
},
1463+
"plugins": {
1464+
"acl": {
1465+
"allow_labels": {
1466+
"team": ["cloud"]
1467+
},
1468+
"external_user_label_field": "$..([invalid",
1469+
"rejected_code": 403
1470+
}
1471+
}
1472+
}]]
1473+
)
1474+
1475+
if code >= 300 then
1476+
ngx.status = code
1477+
end
1478+
ngx.print(body)
1479+
}
1480+
}
1481+
--- request
1482+
GET /t
1483+
--- error_code: 400
1484+
--- response_body_like
1485+
failed to check the configuration of plugin acl err: invalid external_user_label_field:
1486+
1487+
1488+
1489+
=== TEST 54: delete route
14491490
--- config
14501491
location /t {
14511492
content_by_lua_block {
@@ -1463,7 +1504,7 @@ passed
14631504
14641505
14651506
1466-
=== TEST 54: delete jack
1507+
=== TEST 55: delete jack
14671508
--- config
14681509
location /t {
14691510
content_by_lua_block {
@@ -1481,7 +1522,7 @@ passed
14811522
14821523
14831524
1484-
=== TEST 55: delete rose
1525+
=== TEST 56: delete rose
14851526
--- config
14861527
location /t {
14871528
content_by_lua_block {

0 commit comments

Comments
 (0)