Skip to main content
Version: dev

Security

Use this page when a C++ reader accepts bytes from outside the application's trust boundary. Fory reconstructs application values; it does not authenticate the sender, protect transport integrity, or decide whether a valid value is authorized for a business operation.

Application boundary

Before deserialization:

  • Authenticate the sender and protect message integrity at the transport or storage layer.
  • Enforce request or file size, timeout, and concurrency limits outside Fory.
  • Register only the application types the endpoint accepts and configure the reader before its first root operation.
  • Validate the deserialized value against application authorization and domain rules before use.

Built-in safeguards

Security-related configuration:

  • Register all structs and polymorphic implementations before deserializing untrusted payloads.
  • Use check_struct_version(true) with compatible(false) for intentional same-schema payloads.
  • Keep max_graph_memory_bytes(...) at the fixed 128 MiB default for most inputs, or set a positive value for a trusted workload that needs a different collection/map/struct gate.
  • Keep max_dyn_depth(...) as low as your model permits to reject unexpectedly deep polymorphic graphs.
  • Keep the remote schema metadata limits at their defaults unless the data is not malicious and a trusted peer sends larger metadata or many schema versions.
  • Prefer concrete fields over broad polymorphic fields for untrusted input.

Verification

Add negative tests for the boundary as well as normal round trips. Verify that the configured reader rejects unexpected application types, excessive nesting, resource-limit violations, and malformed input. After a failed read, verify that a valid root can still be read with the same Fory instance.

See Configuration for the complete option reference and Type Registration for the Fory registration API.