RpcSecurityPolicy class final
Centralized security/robustness limits for transports and parsers.
The goal is to provide consistent defaults across all built-in transports and to make resource-exhaustion and injection-style attacks harder.
This is not authentication/authorization. It is purely about input validation and resource limits.
Constructors
- RpcSecurityPolicy({int maxMessageLengthBytes = _defaultMaxMessageLengthBytes, int? maxBufferedBytes, int maxMessagesPerChunk = _defaultMaxMessagesPerChunk, int maxDecodedItems = _defaultMaxDecodedItems, int maxBufferedMessagesPerStream = _defaultMaxBufferedMessagesPerStream, int maxActiveStreams = _defaultMaxActiveStreams, int? maxConcurrentHandlers, int maxMetadataBytes = _defaultMaxMetadataBytes, int maxHeaders = _defaultMaxHeaders, int maxHeaderNameBytes = _defaultMaxHeaderNameBytes, int maxHeaderValueBytes = _defaultMaxHeaderValueBytes, int maxMethodPathLength = kDefaultMaxMethodPathLength, bool closeOnProtocolError = _defaultCloseOnProtocolError, Duration? halfOpenStreamTimeout = _defaultHalfOpenStreamTimeout, int? flowControlWindowBytes = _defaultFlowControlWindowBytes, int? flowControlConnectionWindowBytes = _defaultFlowControlConnectionWindowBytes, int? initialSendWindowBytes = _defaultInitialSendWindowBytes, Duration? initialSendWindowGrace = _defaultInitialSendWindowGrace, RpcContentTypeValidation contentTypeValidation = _defaultContentTypeValidation})
-
Creates an RpcSecurityPolicy with the given limits.
const
-
RpcSecurityPolicy.fromMap(Map<
String, Object?> map) -
Creates an RpcSecurityPolicy from a plain map, using defaults for missing keys.
factory
Properties
- advertisedWindowBytes → int?
-
The per-stream window this side advertises: flowControlWindowBytes,
or less when effectiveStreamBufferBytes could not hold that much.
no setter
- closeOnProtocolError → bool
-
Close the whole connection on a protocol violation, rather than the call.
final
- contentTypeValidation → RpcContentTypeValidation
-
Whether a request with no
content-typeat all is accepted.final - effectiveConnectionBufferBytes → int?
-
Un-consumed bytes one connection may hold across its streams, or null
when flowControlConnectionWindowBytes is off.
no setter
- effectiveMaxBufferedBytes → int
-
Effective max buffered bytes, falling back to message size + prefix when unset.
no setter
- effectiveStreamBufferBytes → int
-
Un-consumed bytes one stream's queue may hold: maxBufferedBytes when
set, otherwise enough for what flow control lets a peer send.
no setter
- flowControlConnectionWindowBytes → int?
-
Connection-wide flow-control window in bytes, or null to disable.
final
- flowControlWindowBytes → int?
-
Per-stream flow-control window in bytes, or null to disable.
final
- halfOpenStreamTimeout → Duration?
-
How long a peer-opened stream may sit half-open before it is reclaimed.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialSendWindowBytes → int?
-
What a sender may put in flight BEFORE the peer's first grant arrives, or
null to stay unbounded until then.
final
- initialSendWindowGrace → Duration?
-
How long a sender blocked on initialSendWindowBytes waits for the peer's
first grant before concluding the peer does not do flow control at all, or
null to wait forever.
final
- maxActiveStreams → int
-
Max simultaneously active streams, per connection.
final
- maxBufferedBytes → int?
-
Max buffered bytes for reassembly/parsing of fragmented frames.
final
- maxBufferedMessagesPerStream → int
-
Max UN-CONSUMED messages held for one stream.
final
- maxChannelFrameBytes → int
-
The largest channel frame a multiplexed channel reassembles: one
buffered message, effectiveMaxBufferedBytes, under its frame header.
no setter
- maxConcurrentHandlers → int?
-
Max handlers RUNNING at once, per connection; null for no limit.
final
- maxDecodedItems → int
-
Max CBOR data items one inbound message may decode to: each map key,
each value, each container counts one.
final
- maxFramedMessageBytes → int
-
The largest a single gRPC FRAME may be: one message plus its 5-byte prefix.
no setter
- maxHeaderNameBytes → int
-
Max bytes allowed for a header name (defense against pathological input).
final
- maxHeaders → int
-
Max number of headers inside RpcMetadata.
final
- maxHeaderValueBytes → int
-
Max bytes allowed for a header value.
final
- maxMessageLengthBytes → int
-
Max payload size of a single decoded gRPC message.
final
- maxMessagesPerChunk → int
-
Max number of messages emitted from a single incoming chunk.
final
- maxMetadataBytes → int
-
Max size of one INBOUND metadata block, however the transport carries it.
final
- maxMethodPathLength → int
-
Max length of
:path/ methodPath strings.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
isValidHeaderName(
String name) → bool - Header-name validation for transport-level metadata.
-
isValidHeaderValue(
String value) → bool - Header-value validation for transport-level metadata.
-
isValidMethodPath(
String? methodPath) → bool -
Returns true if
methodPathis absent or matches parseMethodPath. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parseMethodPath(
String? methodPath) → (String, String)? -
Splits a valid
/Service/Methodinto its two names, or null. -
statusOnly(
RpcMetadata metadata) → RpcMetadata? - A peer's RESPONSE metadata cut down to the status it carries, or null if it carries none this side can use.
-
toMap(
) → Map< String, Object> - Serializes this policy to a plain map.
-
toString(
) → String -
A string representation of this object.
inherited
-
validateMetadata(
RpcMetadata metadata) → void - Best-effort metadata validation.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
isAcceptableContentType(
String? value, RpcContentTypeValidation mode) → bool -
Whether
valueis an acceptable gRPCcontent-type, absent included.
Constants
- maxPolicyViolations → const int
- How many policy violations one connection may cost before it is closed as hostile rather than misconfigured.