Class: WSDL::Limits
- Inherits:
-
Object
- Object
- WSDL::Limits
- Defined in:
- lib/wsdl/limits.rb
Overview
Configuration for resource limits to prevent denial-of-service attacks.
This class provides sensible defaults that work for most WSDL documents while protecting against malicious or malformed documents that could exhaust system resources.
The library already protects against XXE, SSRF, and path traversal attacks. These limits add protection against resource exhaustion attacks.
Constant Summary collapse
- DEFAULT_MAX_DOCUMENT_SIZE =
Default maximum size for a single WSDL or schema document (10 MB).
10 * 1024 * 1024
- DEFAULT_MAX_TOTAL_DOWNLOAD_SIZE =
Default maximum cumulative bytes downloaded across all documents (50 MB).
50 * 1024 * 1024
- DEFAULT_MAX_SCHEMAS =
Default maximum number of schema definitions allowed.
50- DEFAULT_MAX_ELEMENTS_PER_TYPE =
Default maximum child elements in a complex type.
500- DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT =
Default maximum attributes on an XML element.
100- DEFAULT_MAX_TYPE_NESTING_DEPTH =
Default maximum depth of type inheritance/nesting.
50- DEFAULT_MAX_REQUEST_ELEMENTS =
Default maximum total elements in request envelope construction.
10_000- DEFAULT_MAX_REQUEST_DEPTH =
Default maximum request envelope nesting depth.
100- DEFAULT_MAX_REQUEST_ATTRIBUTES =
Default maximum total attributes in request envelope construction.
1_000- DEFAULT_MAX_SCHEMA_IMPORT_ITERATIONS =
Default maximum iterations for resolving schema imports and includes.
100- DEFAULT_MAX_RESPONSE_SIZE =
Default maximum size for a SOAP response body (10 MB).
10 * 1024 * 1024
Instance Attribute Summary collapse
-
#max_attributes_per_element ⇒ Integer?
readonly
Maximum attributes on an XML element.
-
#max_document_size ⇒ Integer?
readonly
Maximum size in bytes for a single WSDL/schema document.
-
#max_elements_per_type ⇒ Integer?
readonly
Maximum child elements in a complex type.
-
#max_request_attributes ⇒ Integer?
readonly
Maximum total attributes in request envelope.
-
#max_request_depth ⇒ Integer?
readonly
Maximum request envelope nesting depth.
-
#max_request_elements ⇒ Integer?
readonly
Maximum total elements in request envelope.
-
#max_response_size ⇒ Integer?
readonly
Maximum size in bytes for a SOAP response body.
-
#max_schema_import_iterations ⇒ Integer?
readonly
Maximum iterations for resolving schema imports and includes.
-
#max_schemas ⇒ Integer?
readonly
Maximum number of schema definitions.
-
#max_total_download_size ⇒ Integer?
readonly
Maximum cumulative bytes downloaded.
-
#max_type_nesting_depth ⇒ Integer?
readonly
Maximum depth of type inheritance/nesting.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #eql?)
Checks equality with another Limits instance.
-
#hash ⇒ Integer
Returns a hash code for use in Hash keys.
-
#initialize(max_document_size: DEFAULT_MAX_DOCUMENT_SIZE, max_total_download_size: DEFAULT_MAX_TOTAL_DOWNLOAD_SIZE, max_schemas: DEFAULT_MAX_SCHEMAS, max_elements_per_type: DEFAULT_MAX_ELEMENTS_PER_TYPE, max_attributes_per_element: DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT, max_type_nesting_depth: DEFAULT_MAX_TYPE_NESTING_DEPTH, max_request_elements: DEFAULT_MAX_REQUEST_ELEMENTS, max_request_depth: DEFAULT_MAX_REQUEST_DEPTH, max_request_attributes: DEFAULT_MAX_REQUEST_ATTRIBUTES, max_schema_import_iterations: DEFAULT_MAX_SCHEMA_IMPORT_ITERATIONS, max_response_size: DEFAULT_MAX_RESPONSE_SIZE) ⇒ Limits
constructor
Creates a new Limits instance with the specified resource limits.
-
#inspect ⇒ String
Returns a human-readable string representation.
-
#to_h ⇒ Hash{Symbol => Integer, nil}
Returns a hash representation of the limits.
-
#with(**options) ⇒ Limits
Creates a new Limits instance with some values changed.
Constructor Details
#initialize(max_document_size: DEFAULT_MAX_DOCUMENT_SIZE, max_total_download_size: DEFAULT_MAX_TOTAL_DOWNLOAD_SIZE, max_schemas: DEFAULT_MAX_SCHEMAS, max_elements_per_type: DEFAULT_MAX_ELEMENTS_PER_TYPE, max_attributes_per_element: DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT, max_type_nesting_depth: DEFAULT_MAX_TYPE_NESTING_DEPTH, max_request_elements: DEFAULT_MAX_REQUEST_ELEMENTS, max_request_depth: DEFAULT_MAX_REQUEST_DEPTH, max_request_attributes: DEFAULT_MAX_REQUEST_ATTRIBUTES, max_schema_import_iterations: DEFAULT_MAX_SCHEMA_IMPORT_ITERATIONS, max_response_size: DEFAULT_MAX_RESPONSE_SIZE) ⇒ Limits
Creates a new Limits instance with the specified resource limits.
rubocop:disable Metrics/ParameterLists
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/wsdl/limits.rb', line 87 def initialize( max_document_size: DEFAULT_MAX_DOCUMENT_SIZE, max_total_download_size: DEFAULT_MAX_TOTAL_DOWNLOAD_SIZE, max_schemas: DEFAULT_MAX_SCHEMAS, max_elements_per_type: DEFAULT_MAX_ELEMENTS_PER_TYPE, max_attributes_per_element: DEFAULT_MAX_ATTRIBUTES_PER_ELEMENT, max_type_nesting_depth: DEFAULT_MAX_TYPE_NESTING_DEPTH, max_request_elements: DEFAULT_MAX_REQUEST_ELEMENTS, max_request_depth: DEFAULT_MAX_REQUEST_DEPTH, max_request_attributes: DEFAULT_MAX_REQUEST_ATTRIBUTES, max_schema_import_iterations: DEFAULT_MAX_SCHEMA_IMPORT_ITERATIONS, max_response_size: DEFAULT_MAX_RESPONSE_SIZE ) # rubocop:enable Metrics/ParameterLists @max_document_size = max_document_size @max_total_download_size = max_total_download_size @max_schemas = max_schemas @max_elements_per_type = max_elements_per_type @max_attributes_per_element = max_attributes_per_element @max_type_nesting_depth = max_type_nesting_depth @max_request_elements = max_request_elements @max_request_depth = max_request_depth @max_request_attributes = max_request_attributes @max_schema_import_iterations = max_schema_import_iterations @max_response_size = max_response_size freeze end |
Instance Attribute Details
#max_attributes_per_element ⇒ Integer? (readonly)
Returns maximum attributes on an XML element.
129 130 131 |
# File 'lib/wsdl/limits.rb', line 129 def max_attributes_per_element @max_attributes_per_element end |
#max_document_size ⇒ Integer? (readonly)
Returns maximum size in bytes for a single WSDL/schema document.
117 118 119 |
# File 'lib/wsdl/limits.rb', line 117 def max_document_size @max_document_size end |
#max_elements_per_type ⇒ Integer? (readonly)
Returns maximum child elements in a complex type.
126 127 128 |
# File 'lib/wsdl/limits.rb', line 126 def max_elements_per_type @max_elements_per_type end |
#max_request_attributes ⇒ Integer? (readonly)
Returns maximum total attributes in request envelope.
141 142 143 |
# File 'lib/wsdl/limits.rb', line 141 def max_request_attributes @max_request_attributes end |
#max_request_depth ⇒ Integer? (readonly)
Returns maximum request envelope nesting depth.
138 139 140 |
# File 'lib/wsdl/limits.rb', line 138 def max_request_depth @max_request_depth end |
#max_request_elements ⇒ Integer? (readonly)
Returns maximum total elements in request envelope.
135 136 137 |
# File 'lib/wsdl/limits.rb', line 135 def max_request_elements @max_request_elements end |
#max_response_size ⇒ Integer? (readonly)
Returns maximum size in bytes for a SOAP response body.
147 148 149 |
# File 'lib/wsdl/limits.rb', line 147 def max_response_size @max_response_size end |
#max_schema_import_iterations ⇒ Integer? (readonly)
Returns maximum iterations for resolving schema imports and includes.
144 145 146 |
# File 'lib/wsdl/limits.rb', line 144 def max_schema_import_iterations @max_schema_import_iterations end |
#max_schemas ⇒ Integer? (readonly)
Returns maximum number of schema definitions.
123 124 125 |
# File 'lib/wsdl/limits.rb', line 123 def max_schemas @max_schemas end |
#max_total_download_size ⇒ Integer? (readonly)
Returns maximum cumulative bytes downloaded.
120 121 122 |
# File 'lib/wsdl/limits.rb', line 120 def max_total_download_size @max_total_download_size end |
#max_type_nesting_depth ⇒ Integer? (readonly)
Returns maximum depth of type inheritance/nesting.
132 133 134 |
# File 'lib/wsdl/limits.rb', line 132 def max_type_nesting_depth @max_type_nesting_depth end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: eql?
Checks equality with another Limits instance.
234 235 236 237 238 |
# File 'lib/wsdl/limits.rb', line 234 def ==(other) return false unless other.is_a?(Limits) to_h == other.to_h end |
#hash ⇒ Integer
Returns a hash code for use in Hash keys.
246 247 248 |
# File 'lib/wsdl/limits.rb', line 246 def hash to_h.hash end |
#inspect ⇒ String
Returns a human-readable string representation.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/wsdl/limits.rb', line 211 def inspect parts = { max_document_size: Formatting.format_bytes(@max_document_size), max_total_download_size: Formatting.format_bytes(@max_total_download_size), max_schemas: limit_value(@max_schemas), max_elements_per_type: limit_value(@max_elements_per_type), max_attributes_per_element: limit_value(@max_attributes_per_element), max_type_nesting_depth: limit_value(@max_type_nesting_depth), max_request_elements: limit_value(@max_request_elements), max_request_depth: limit_value(@max_request_depth), max_request_attributes: limit_value(@max_request_attributes), max_schema_import_iterations: limit_value(@max_schema_import_iterations), max_response_size: Formatting.format_bytes(@max_response_size) }.map { |key, value| "#{key}=#{value}" }.join(' ') "#<#{self.class.name} #{parts}>" end |
#to_h ⇒ Hash{Symbol => Integer, nil}
Returns a hash representation of the limits.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/wsdl/limits.rb', line 191 def to_h { max_document_size: @max_document_size, max_total_download_size: @max_total_download_size, max_schemas: @max_schemas, max_elements_per_type: @max_elements_per_type, max_attributes_per_element: @max_attributes_per_element, max_type_nesting_depth: @max_type_nesting_depth, max_request_elements: @max_request_elements, max_request_depth: @max_request_depth, max_request_attributes: @max_request_attributes, max_schema_import_iterations: @max_schema_import_iterations, max_response_size: @max_response_size } end |
#with(**options) ⇒ Limits
Creates a new Limits instance with some values changed.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/wsdl/limits.rb', line 171 def with(**) self.class.new( max_document_size: .fetch(:max_document_size, @max_document_size), max_total_download_size: .fetch(:max_total_download_size, @max_total_download_size), max_schemas: .fetch(:max_schemas, @max_schemas), max_elements_per_type: .fetch(:max_elements_per_type, @max_elements_per_type), max_attributes_per_element: .fetch(:max_attributes_per_element, @max_attributes_per_element), max_type_nesting_depth: .fetch(:max_type_nesting_depth, @max_type_nesting_depth), max_request_elements: .fetch(:max_request_elements, @max_request_elements), max_request_depth: .fetch(:max_request_depth, @max_request_depth), max_request_attributes: .fetch(:max_request_attributes, @max_request_attributes), max_schema_import_iterations: .fetch(:max_schema_import_iterations, @max_schema_import_iterations), max_response_size: .fetch(:max_response_size, @max_response_size) ) end |