symfony/yaml
Symfony Yaml component for parsing, loading, and dumping YAML documents in PHP. Supports reading YAML files/strings and exporting arrays/objects to YAML with configurable formatting, inline levels, and error handling. Includes comprehensive docs and Symfony integration.
symfony/yaml package remains a batteries-included solution for YAML parsing/dumping in Laravel, with seamless alignment to Symfony’s ecosystem (already leveraged via symfony/var-dumper and symfony/console).phpstan/phpstan package is now a soft dependency for the PHPStan rule (only required if using PHPStan).Yaml::parse()/Yaml::dump() methods remain identical.UnsafeUnserialize) is opt-in and does not affect runtime behavior.UnsafeUnserialize) proactively detects YAML files that could trigger unsafe deserialization (e.g., via !!php/object or !!php/unserialized). This mitigates a critical attack vector (e.g., CVE-2026-45305 follow-ups).!!php/object) are still risky unless explicitly disabled (Yaml::parse($yaml, [], 10, null, true)).!!php/object tags break if the rule is enforced?Yaml::parse($yaml, [], 10, null, true)) and using JSON for untrusted data.phpstan.neon:
includes:
- vendor/symfony/yaml/PHPStan/UnsafeUnserialize.neon
use Symfony\Component\Yaml\Yaml;
class YamlUnsafeTagRule extends Rule
{
public function passes($attribute, $value)
{
return !str_contains($value, '!!php/');
}
}
spatie/laravel-data for secure config validation.pestphp/pest to auto-fail tests on unsafe YAML.Phase 1: Security Audit (No Code Changes)
composer require --dev phpstan/phpstan
vendor/bin/phpstan analyse --level=5
phpstan.neon:
arguments:
paths:
- config/
- '!config/untrusted.yaml'
Phase 2: Runtime Safeguards (Optional)
use Illuminate\Support\Facades\Validator;
$validator = Validator::make(['yaml' => $yamlContent], [
'yaml' => ['unsafe_yaml', rule: new YamlUnsafeTagRule],
]);
Phase 3: Enforce in CI
composer require --dev phpstan/phpstan:^1.12
composer require --dev symfony/yaml phpstan/phpstan
phpstan.neon to include the rule and whitelist safe files.YamlUnsafeTagRule and integrate with Laravel’s validator.File config/untrusted.yaml contains unsafe YAML tags (e.g., !!php/object).
Yaml::parse($yaml, [], 10, null, true) to disable custom tags if needed.yamllint before parsing to catch syntax issues.Yaml::parse()/Yaml::dump().| Scenario | Impact | Mitigation |
|---|---|---|
| Unsafe YAML in CI | Build failures | Whitelist trusted files in PHPStan. |
| False Positives | Legitimate YAML blocked | Adjust PHPStan config or use runtime validation. |
| PHPStan Version Mismatch | Rule not loaded | Pin PHPStan version in composer.json. |
| Custom Tag Exploits | Security vulnerabilities | Disable custom tags (Yaml::parse(..., true)) or use JSON for untrusted data. |
!!php/object).// Safe YAML parsing (disables custom tags)
$data = Yaml::parse($yamlContent, [], 10, null, true);
How can I help you explore Laravel packages today?