fix(运行时): 将插件路径匹配移到宿主
新增宿主侧精确路径匹配和插件级 match.paths 配置。\n按请求路径固定插件会话链,移除 Lua 插件内的路径判断与 bypass 状态,并迁移现有插件配置和测试。
This commit is contained in:
1 parent
f905aa22cc
commit
d1f5f69454
12 files changed
+126
-200
No files matched your search
@@ -108,45 +108,14 @@ function plugin.init(ctx, options)
|
||||
end
|
||||
end
|
||||
|
||||
-- 新增:路径白名单(可选)。未配置时保持原行为——对所有含 message
|
||||
-- 字段的请求打标;配置后只有命中白名单的 AI 路径才改写,
|
||||
-- 非 AI 路径(即使恰好有 message 字段)原样放行,不被加前缀。
|
||||
local paths = {}
|
||||
if options.paths ~= nil then
|
||||
if type(options.paths) ~= "table" then
|
||||
error("request_rewrite config.paths must be an array")
|
||||
end
|
||||
local count = 0
|
||||
for _, p in ipairs(options.paths) do
|
||||
if type(p) ~= "string" or p == "" or p:sub(1, 1) ~= "/" then
|
||||
error("request_rewrite config.paths entries must be non-empty path strings")
|
||||
end
|
||||
paths[p] = true
|
||||
count = count + 1
|
||||
end
|
||||
if count == 0 then
|
||||
error("request_rewrite config.paths must be non-empty when present")
|
||||
end
|
||||
end
|
||||
|
||||
-- Atomically replace local settings; don't retain the caller's config table.
|
||||
settings = { prefix = prefix, paths = paths }
|
||||
settings = { prefix = prefix }
|
||||
|
||||
-- plugins.md requires init to return nil.
|
||||
return nil
|
||||
end
|
||||
|
||||
function plugin.on_request(ctx, request)
|
||||
-- 新增:路径白名单判断。放在 body 检查之前,保证无 body 的
|
||||
-- 非 AI 请求(GET /health 等)也能通过,且不会被误加前缀。
|
||||
-- 未配置 paths 时此分支不生效,行为与原版完全一致。
|
||||
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 object" }
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user