class Amber::Configuration::ParamsConfig

Overview

Bounds on the request parameters Amber parses from query strings, URL-encoded bodies, and multipart fields.

Every limit has a safe default, so an application that never mentions this section is protected. A request that exceeds a limit is answered with 400 Bad Request and never allocates in proportion to a number written inside the request.

# config/environments/production.yml
params:
  max_array_index: 250
  max_params: 2000

Each value can also be set with an AMBER_PARAMS_<KEY> environment variable, for example AMBER_PARAMS_MAX_ARRAY_INDEX=250.

Included Modules

Defined in:

amber/configuration/params_config.cr

Constant Summary

INT32_RANGES = {"max_array_index" => 0..1000000, "max_array_index_gap" => 0..1000000, "max_array_padding" => 0..10000000, "max_params" => 1..1000000, "max_nesting_depth" => 1..1024, "max_key_bytes" => 1..1048576, "max_value_bytes" => 1..268435456, "max_form_body_bytes" => 1..1073741824, "max_part_header_bytes" => 1..1048576, "max_websocket_message_bytes" => 125..1073741824, "max_document_body_bytes" => 1..1073741824}

The accepted range of each limit. The ranges keep every limit far from integer overflow and reject settings that would disable a limit.

INT64_RANGES = {"max_multipart_body_bytes" => 1_i64..68719476736_i64, "max_multipart_restore_bytes" => 0_i64..68719476736_i64, "max_file_bytes" => 1_i64..1073741824_i64}

Constructors

Instance Method Summary

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]
def self.new #

[View source]

Instance Method Detail

def max_array_index : Int32 #

The largest index accepted in a bracket key such as items[100].


[View source]
def max_array_index=(max_array_index : Int32) #

The largest index accepted in a bracket key such as items[100].


[View source]
def max_array_index_gap : Int32 #

How far past the current end of an array an index may point. An index farther ahead than this is rejected instead of padding the array with empty entries.


[View source]
def max_array_index_gap=(max_array_index_gap : Int32) #

How far past the current end of an array an index may point. An index farther ahead than this is rejected instead of padding the array with empty entries.


[View source]
def max_array_padding : Int32 #

The total number of empty entries one request may create while filling gaps between array indices.


[View source]
def max_array_padding=(max_array_padding : Int32) #

The total number of empty entries one request may create while filling gaps between array indices.


[View source]
def max_document_body_bytes : Int32 #

The size of a JSON, CBOR, COSE or application-parsed document body that Amber reads for schema validation or params, in bytes.


[View source]
def max_document_body_bytes=(max_document_body_bytes : Int32) #

The size of a JSON, CBOR, COSE or application-parsed document body that Amber reads for schema validation or params, in bytes.


[View source]
def max_file_bytes : Int64 #

The size of one uploaded file, in bytes, counted while it streams. Schema contracts hold uploads in memory, so the accepted range stops at 1 GiB.


[View source]
def max_file_bytes=(max_file_bytes : Int64) #

The size of one uploaded file, in bytes, counted while it streams. Schema contracts hold uploads in memory, so the accepted range stops at 1 GiB.


[View source]
def max_form_body_bytes : Int32 #

The size of a complete application/x-www-form-urlencoded body, in bytes.


[View source]
def max_form_body_bytes=(max_form_body_bytes : Int32) #

The size of a complete application/x-www-form-urlencoded body, in bytes.


[View source]
def max_key_bytes : Int32 #

The length of one parameter name, in bytes.


[View source]
def max_key_bytes=(max_key_bytes : Int32) #

The length of one parameter name, in bytes.


[View source]
def max_multipart_body_bytes : Int64 #

The size of a complete multipart/form-data body, in bytes, counted while it streams.


[View source]
def max_multipart_body_bytes=(max_multipart_body_bytes : Int64) #

The size of a complete multipart/form-data body, in bytes, counted while it streams.


[View source]
def max_multipart_restore_bytes : Int64 #

The largest multipart body, in bytes, that Amber copies to a tempfile so request.body can be read again after the form is parsed. Amber parses the body before the action runs (the CSRF pipe reads _csrf from params), which drains it; the copy hands the action the bytes the client sent. A body is copied only when its declared Content-Length is within this limit and #max_multipart_body_bytes; a larger body, or one without Content-Length, stays drained. 0 turns the copy off.


[View source]
def max_multipart_restore_bytes=(max_multipart_restore_bytes : Int64) #

The largest multipart body, in bytes, that Amber copies to a tempfile so request.body can be read again after the form is parsed. Amber parses the body before the action runs (the CSRF pipe reads _csrf from params), which drains it; the copy hands the action the bytes the client sent. A body is copied only when its declared Content-Length is within this limit and #max_multipart_body_bytes; a larger body, or one without Content-Length, stays drained. 0 turns the copy off.


[View source]
def max_nesting_depth : Int32 #

The number of segments in one key: a[b][c] has three.


[View source]
def max_nesting_depth=(max_nesting_depth : Int32) #

The number of segments in one key: a[b][c] has three.


[View source]
def max_params : Int32 #

The number of parameters (fields and uploads) one request may carry.


[View source]
def max_params=(max_params : Int32) #

The number of parameters (fields and uploads) one request may carry.


[View source]
def max_part_header_bytes : Int32 #

The size of one multipart part's boundary line and headers, in bytes.


[View source]
def max_part_header_bytes=(max_part_header_bytes : Int32) #

The size of one multipart part's boundary line and headers, in bytes.


[View source]
def max_value_bytes : Int32 #

The length of one parameter value, in bytes. Uploaded files are not counted here.


[View source]
def max_value_bytes=(max_value_bytes : Int32) #

The length of one parameter value, in bytes. Uploaded files are not counted here.


[View source]
def max_websocket_message_bytes : Int32 #

The size of one incoming WebSocket message, in bytes, counted across its frames and fragments as they arrive.


[View source]
def max_websocket_message_bytes=(max_websocket_message_bytes : Int32) #

The size of one incoming WebSocket message, in bytes, counted across its frames and fragments as they arrive.


[View source]
def validate! : Nil #

[View source]