fix(运行时): 将插件路径匹配移到宿主

新增宿主侧精确路径匹配和插件级 match.paths 配置。\n按请求路径固定插件会话链,移除 Lua 插件内的路径判断与 bypass 状态,并迁移现有插件配置和测试。
This commit is contained in:
starrrLight committed 2026-10-15 15:49:05 +08:00
1 parent f905aa22cc
commit d1f5f69454
12 files changed
+126 -200

No files matched your search

-31
View File
@@ -96,46 +96,15 @@ function plugin.init(ctx, options)
end
end
-- 新增:路径白名单(可选)。未配置时保持原行为——审核所有请求;
-- 配置后只有命中白名单的路径才走外发审核,其余请求直接放行。
local paths = {}
if options.paths ~= nil then
if type(options.paths) ~= "table" then
error("network_review config.paths must be an array")
end
local seen_paths = {}
for _, p in ipairs(options.paths) do
if not is_non_empty_string(p) or p:sub(1, 1) ~= "/" then
error("network_review config.paths entries must be non-empty path strings")
end
if seen_paths[p] then
error("network_review config.paths contains a duplicate path")
end
seen_paths[p] = true
paths[p] = true
end
end
settings = {
url = options.url,
fields = fields,
headers = headers,
paths = paths,
}
return nil
end
function plugin.on_request(ctx, request)
-- 新增:路径白名单判断。必须放在 body 检查之前,否则 GET /health 这类
-- 无 body 的非 AI 请求会被 "invalid request body" 拦截。
-- 未配置 paths 时此分支不生效,行为与原版完全一致(fail-closed 审核一切)。
if next(settings.paths) ~= nil then
local path = type(request) == "table" and request.path or nil
if path == nil or not settings.paths[path] then
return { action = "pass" }
end
end
if type(request) ~= "table" or type(request.body) ~= "string" then
return { action = "block", reason = "invalid request body" }
end