Class YmlSafeLoader
java.lang.Object
cloud.opencode.base.yml.security.YmlSafeLoader
YAML Safe Loader - Provides secure YAML loading
YAML 安全加载器 - 提供安全的 YAML 加载
This class provides utilities for safely loading YAML without arbitrary code execution risks.
此类提供安全加载 YAML 的工具,避免任意代码执行风险。
Features | 主要功能:
- Configurable allowed types and denied tags - 可配置的允许类型和拒绝标签
- Maximum depth, size, and alias limits - 最大深度、大小和别名限制
- Cyclic reference detection - 循环引用检测
Usage Examples | 使用示例:
// Configure allowed types
YmlSafeLoader loader = YmlSafeLoader.builder()
.allowType(MyClass.class)
.maxDepth(100)
.maxSize(1_000_000)
.build();
// Validate data
loader.validate(data);
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构建后不可变)
- Null-safe: No (null data skips validation) - 空值安全: 否(空数据跳过验证)
- Since:
- JDK 25, opencode-base-yml V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSafe Loader Builder 安全加载器构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic YmlSafeLoader.Builderbuilder()Creates a builder for safe loader.static YmlSafeLoadercreate()Creates a default safe loader.intGets the maximum aliases.intGets the maximum depth.intGets the maximum size.booleanisAllowedType(Class<?> type) Checks if a type is allowed.booleanisDeniedTag(String tag) Checks if a tag is denied.voidValidates that data is safe.
-
Method Details
-
create
Creates a default safe loader. 创建默认的安全加载器。- Returns:
- a safe loader | 安全加载器
-
builder
Creates a builder for safe loader. 创建安全加载器的构建器。- Returns:
- a new builder | 新构建器
-
validate
Validates that data is safe. 验证数据是否安全。- Parameters:
data- the data to validate | 要验证的数据- Throws:
YmlSecurityException- if data is not safe | 如果数据不安全
-
isAllowedType
Checks if a type is allowed. 检查类型是否被允许。- Parameters:
type- the type to check | 要检查的类型- Returns:
- true if allowed | 如果允许则返回 true
-
isDeniedTag
Checks if a tag is denied. 检查标签是否被拒绝。- Parameters:
tag- the tag to check | 要检查的标签- Returns:
- true if denied | 如果被拒绝则返回 true
-
getMaxDepth
public int getMaxDepth()Gets the maximum depth. 获取最大深度。- Returns:
- the max depth | 最大深度
-
getMaxSize
public int getMaxSize()Gets the maximum size. 获取最大大小。- Returns:
- the max size | 最大大小
-
getMaxAliases
public int getMaxAliases()Gets the maximum aliases. 获取最大别名数。- Returns:
- the max aliases | 最大别名数
-