Skip to content
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
13 changes: 10 additions & 3 deletions apisix/plugins/ai-prompt-decorator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ local prompts = {
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
prepend = prompts,
append = prompts,
},
Expand All @@ -64,8 +71,8 @@ function _M.check_schema(conf)
end


local function get_request_body_table()
local body, err = core.request.get_body()
local function get_request_body_table(max_size)
local body, err = core.request.get_body(max_size)
if not body then
return nil, { message = "could not get body: " .. (err or "request body is empty") }
end
Expand All @@ -80,7 +87,7 @@ end


function _M.rewrite(conf, ctx)
local body_tab, err = get_request_body_table()
local body_tab, err = get_request_body_table(conf.max_req_body_size)
if not body_tab then
return 400, err
end
Expand Down
9 changes: 8 additions & 1 deletion apisix/plugins/ai-prompt-guard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ local plugin_name = "ai-prompt-guard"
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
match_all_roles = {
type = "boolean",
default = false,
Expand Down Expand Up @@ -98,7 +105,7 @@ end


function _M.access(conf, ctx)
local body = core.request.get_body()
local body = core.request.get_body(conf.max_req_body_size)
if not body then
core.log.error("Empty request body")
return 400, {message = "Empty request body"}
Expand Down
13 changes: 10 additions & 3 deletions apisix/plugins/ai-prompt-template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ local prompts = {
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
templates = {
type = "array",
minItems = 1,
Expand Down Expand Up @@ -90,8 +97,8 @@ function _M.check_schema(conf)
end


local function get_request_body_table()
local body, err = core.request.get_body()
local function get_request_body_table(max_size)
local body, err = core.request.get_body(max_size)
if not body then
return nil, { message = "could not get body: " .. (err or "request body is empty") }
end
Expand All @@ -115,7 +122,7 @@ local function find_template(conf, template_name)
end

function _M.rewrite(conf, ctx)
local body_tab, err = get_request_body_table()
local body_tab, err = get_request_body_table(conf.max_req_body_size)
if not body_tab then
return 400, err
end
Expand Down
4 changes: 2 additions & 2 deletions apisix/plugins/ai-proxy/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ _M.ai_proxy_schema = {
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes the plugin reads "
.. "into memory; larger requests are rejected with 413. "
.. "into memory; larger request bodies are rejected. "
.. "Prevents unbounded memory buffering of large bodies.",
},
max_stream_duration_ms = {
Expand Down Expand Up @@ -373,7 +373,7 @@ _M.ai_proxy_multi_schema = {
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes the plugin reads "
.. "into memory; larger requests are rejected with 413. "
.. "into memory; larger request bodies are rejected. "
.. "Prevents unbounded memory buffering of large bodies.",
},
max_stream_duration_ms = {
Expand Down
9 changes: 8 additions & 1 deletion apisix/plugins/ai-request-rewrite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ local model_options_schema = {
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
prompt = {
type = "string",
description = "The prompt to rewrite client request."
Expand Down Expand Up @@ -172,7 +179,7 @@ function _M.check_schema(conf)
end

function _M.access(conf, ctx)
local client_request_body, err = core.request.get_body()
local client_request_body, err = core.request.get_body(conf.max_req_body_size)
if err then
core.log.warn("failed to get request body: ", err)
return HTTP_BAD_REQUEST
Expand Down
9 changes: 8 additions & 1 deletion apisix/plugins/authz-keycloak.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ local pairs = pairs
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
discovery = {type = "string", minLength = 1, maxLength = 4096},
token_endpoint = {type = "string", minLength = 1, maxLength = 4096},
resource_registration_endpoint = {type = "string", minLength = 1, maxLength = 4096},
Expand Down Expand Up @@ -694,7 +701,7 @@ end
local function generate_token_using_password_grant(conf,ctx)
log.debug("generate_token_using_password_grant Function Called")

local body, err = core.request.get_body()
local body, err = core.request.get_body(conf.max_req_body_size)
if err or not body then
log.error("Failed to get request body: ", err)
return 503
Expand Down
22 changes: 20 additions & 2 deletions apisix/plugins/body-transformer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ local schema = {
properties = {
request = transform_schema,
response = transform_schema,
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
max_resp_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum response body size in bytes buffered into "
.. "memory; larger responses are truncated",
},
},
anyOf = {
{required = {"request"}},
Expand Down Expand Up @@ -233,7 +247,11 @@ function _M.rewrite(conf, ctx)
local request_method = ngx.var.request_method
conf = core.table.deepcopy(conf)
ctx.body_transformer_conf = conf
local body = core.request.get_body()
local body, err = core.request.get_body(conf.max_req_body_size)
if err then
core.log.error("failed to get request body: ", err)
return 413
end
set_input_format(conf, "request", ctx.var.http_content_type, request_method)
local out, status, err = transform(conf, body, "request", ctx, request_method)
if not out then
Expand Down Expand Up @@ -262,7 +280,7 @@ function _M.body_filter(_, ctx)
return
end
if conf.response then
local body = core.response.hold_body_chunk(ctx)
local body = core.response.hold_body_chunk(ctx, false, conf.max_resp_body_size)
if ngx.arg[2] == false and not body then
return
end
Expand Down
9 changes: 8 additions & 1 deletion apisix/plugins/cas-auth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ local plugin_name = "cas-auth"
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
idp_uri = {type = "string"},
cas_callback_uri = {
type = "string",
Expand Down Expand Up @@ -358,7 +365,7 @@ function _M.access(conf, ctx)
end

if method == "POST" and uri == cas_callback_path then
local data = core.request.get_body()
local data = core.request.get_body(conf.max_req_body_size)
local ticket = data and data:match("<samlp:SessionIndex>(.+)</samlp:SessionIndex>")
if ticket == nil then
return ngx.HTTP_BAD_REQUEST,
Expand Down
11 changes: 9 additions & 2 deletions apisix/plugins/degraphql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ local type = type
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
query = {
type = "string",
minLength = 1,
Expand Down Expand Up @@ -75,7 +82,7 @@ end


local function fetch_post_variables(conf)
local req_body, err = core.request.get_body()
local req_body, err = core.request.get_body(conf.max_req_body_size)
if err ~= nil then
core.log.error("failed to get request body: ", err)
return nil, 503
Expand Down Expand Up @@ -146,7 +153,7 @@ function _M.access(conf, ctx)
if meth == "POST" then
if not conf.variables then
-- the set_body_data requires to read the body first
core.request.get_body()
core.request.get_body(conf.max_req_body_size)
end

core.request.set_header(ctx, "Content-Type", "application/json")
Expand Down
10 changes: 9 additions & 1 deletion apisix/plugins/grpc-transcode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ local pb_option_def = {
local schema = {
type = "object",
properties = {
max_resp_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum response body size in bytes buffered into "
.. "memory for transcoding; larger responses are truncated",
},
proto_id = schema_def.id_schema,
service = {
description = "the grpc service name",
Expand Down Expand Up @@ -200,7 +207,8 @@ function _M.body_filter(conf, ctx)
end

local err = response(ctx, proto_obj, conf.service, conf.method, conf.pb_option,
conf.show_status_in_body, conf.status_detail_type)
conf.show_status_in_body, conf.status_detail_type,
conf.max_resp_body_size)
if err then
core.log.error("transform response error: ", err)
return
Expand Down
5 changes: 3 additions & 2 deletions apisix/plugins/grpc-transcode/response.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ local function handle_error_response(status_detail_type, proto)
end


return function(ctx, proto, service, method, pb_option, show_status_in_body, status_detail_type)
local buffer = core.response.hold_body_chunk(ctx)
return function(ctx, proto, service, method, pb_option, show_status_in_body, status_detail_type,
max_resp_body_size)
local buffer = core.response.hold_body_chunk(ctx, false, max_resp_body_size)
if not buffer then
return nil
end
Expand Down
9 changes: 8 additions & 1 deletion apisix/plugins/grpc-web.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ local plugin_name = "grpc-web"
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
cors_allow_headers = {
description =
"multiple header use ',' to split. default: content-type,x-grpc-web,x-user-agent.",
Expand Down Expand Up @@ -143,7 +150,7 @@ function _M.access(conf, ctx)
end

-- set grpc body
local body, err = core.request.get_body()
local body, err = core.request.get_body(conf.max_req_body_size)
if err or not body then
core.log.error("failed to read request body, err: ", err)
return exit(ctx, 400)
Expand Down
26 changes: 23 additions & 3 deletions apisix/plugins/http-dubbo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ local plugin_name = "http-dubbo"
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
service_name = {
type = "string",
minLength = 1,
Expand Down Expand Up @@ -174,15 +181,24 @@ local function get_dubbo_request(conf, ctx)
serialized = serialization_header == "true"
end
if serialized then
params = core.request.get_body()
local body, err = core.request.get_body(conf.max_req_body_size)
if err then
core.log.error("failed to get request body: ", err)
return nil, 413
end
params = body
if params then
local end_of_params = core.string.sub(params, -1)
if end_of_params ~= "\n" then
params = params .. "\n"
end
end
else
local body_data = core.request.get_body()
local body_data, err = core.request.get_body(conf.max_req_body_size)
if err then
core.log.error("failed to get request body: ", err)
return nil, 413
end
if body_data then
local lua_object = core.json.decode(body_data);
for _, v in pairs(lua_object) do
Expand Down Expand Up @@ -231,7 +247,11 @@ function _M.before_proxy(conf, ctx)
core.log.error("failed to connect to upstream ", err)
return 502
end
local request = get_dubbo_request(conf, ctx)
local request, err_code = get_dubbo_request(conf, ctx)
if not request then
sock:close()
return err_code
end
local bytes, _ = sock:send(request)
if bytes > 0 then
local header, _ = sock:receiveany(16);
Expand Down
9 changes: 8 additions & 1 deletion apisix/plugins/oas-validator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ local DEFAULT_SPEC_URL_TTL = 3600
local schema = {
type = "object",
properties = {
max_req_body_size = {
type = "integer",
minimum = 1,
default = 67108864,
description = "maximum request body size in bytes buffered into "
.. "memory; larger request bodies are rejected",
},
spec = {
description = "schema against which the request/response will be validated",
type = "string",
Expand Down Expand Up @@ -244,7 +251,7 @@ function _M.access(conf, ctx)

local req_body
if not conf.skip_request_body_validation then
local body, body_err = core.request.get_body()
local body, body_err = core.request.get_body(conf.max_req_body_size)
if body_err ~= nil then
core.log.error("failed reading request body, err: " .. body_err)
return 500, {message = "error reading the request body. err: " .. body_err}
Expand Down
Loading
Loading