title: Security sidebar_position: 99 id: security license: | Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Use this page when a Scala 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.
Before deserialization:
Scala uses the Java configuration surface. Keep class registration enabled for production and any untrusted payload source:
val fory = ForyScala.builder() .requireClassRegistration(true) .withMaxDepth(50) .withMaxGraphMemoryBytes(128L * 1024 * 1024) .withMaxUnbackedContainerItems(8192) .withMaxTypeFields(512) .withMaxTypeMetaBytes(4096) .build()
Security-related configuration:
requireClassRegistration(true) and register application classes or generated modules.withMaxDepth(...) to reject unexpectedly deep object graphs.withMaxGraphMemoryBytes(...) as an approximate gate for collection, map, array, struct, and object-heavy payloads. It is not an exact heap cap; leaf values are gated by remaining input bytes.withMaxUnbackedContainerItems(...) at 8192 unless trusted compact codecs require a larger root allowance. Zero rejects every unbacked item.withMaxTypeFields(...), withMaxTypeMetaBytes(...), and the remote schema-version limits at their defaults unless the data is not malicious and a trusted peer sends larger metadata or many schema versions.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 reusable runtime.
See Configuration for the Scala option reference and Java Type Registration for the underlying registration API.