symfony/yaml
Symfony Yaml Component for parsing and generating YAML. Load YAML files into PHP arrays/objects and dump PHP data back to YAML, with robust support for common YAML features and integration with the Symfony ecosystem.
Security Hardening: The new release (v8.1.0-BETA3) introduces three critical security fixes addressing catastrophic backtracking (CVE-2026-45305), unbound collection-alias resolution (CVE-2026-45304), and unbound recursion depth (CVE-2026-45133) in the YAML parser. These changes are highly aligned with Laravel’s security-first philosophy, particularly for applications processing untrusted YAML inputs (e.g., API payloads, user uploads, or third-party configs).
config/*.yaml or environment-specific files.Symfony Ecosystem Synergy: The fixes reflect Symfony’s proactive security posture, reinforcing Laravel’s reliance on Symfony components. No architectural misalignment; the changes are under-the-hood optimizations with no functional impact on valid YAML.
Yaml::parse()/Yaml::dump() APIs.ConfigRepository).symfony/yaml remains a drop-in replacement).$yaml = Yaml::dump(['key' => 'value', 'nested' => ['array' => true]]);
$parsed = Yaml::parse($yaml);
$this->assertEquals(['key' => 'value', 'nested' => ['array' => true]], $parsed);
$maliciousYaml = str_repeat("key: ", 10000) . "value: test";
$this->expectException(\Symfony\Component\Yaml\Exception\ParseException::class);
Yaml::parse($maliciousYaml);
Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE for strict validation.Untrusted YAML Sources
Recursion-Heavy YAML
&anchor *anchor)?# test_recursive.yaml
root: &ref
self: *ref
$this->expectNotToPerformAssertions(); // Should not hang or crash
Yaml::parseFile('test_recursive.yaml');
Third-Party YAML Libraries
spatie/laravel-medialibrary, php-yaml)? Verify their compatibility with the new parser bounds.CI/CD Pipeline Updates
# .github/workflows/test.yml
- name: Validate YAML
run: php artisan yaml:validate --fail-on-error
Fallback Mechanisms
spatie/yaml-front-matter) if the new bounds cause false positives in edge cases.FormRequest or ApiResource to validate YAML inputs:
// app/Http/Requests/ValidateYamlRequest.php
public function validateYaml($attribute, $value)
{
try {
Yaml::parse($value, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
return true;
} catch (\Exception $e) {
throw new \InvalidArgumentException("Invalid YAML: {$e->getMessage()}");
}
}
yaml:validate command to test for recursion limits and regex bounds:
// app/Console/Commands/ValidateYaml.php
public function handle()
{
$yaml = file_get_contents($this->argument('file'));
$this->info("Testing recursion bounds...");
$this->testRecursiveYaml($yaml);
$this->info("Testing regex safety...");
$this->testRegexBomb($yaml);
}
protected function testRecursiveYaml($yaml)
{
$this->expectNotToPerformAssertions();
Yaml::parse($yaml, Yaml::PARSE_CONSTANT);
}
// app/Http/Middleware/ValidateYamlPayload.php
public function handle($request, Closure $next)
{
if ($request->isYamlPayload()) {
Yaml::parse($request->yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
}
return $next($request);
}
Audit Phase:
git grep -r "Yaml::parse(" --include="*.php" | grep -v "config/"
git grep -r "\*[[:space:]]*&" --include="*.yaml"
Validation Phase:
# .github/workflows/security.yml
- name: Test YAML Security
run: |
php -r "require 'vendor/autoload.php'; \
use Symfony\Component\Yaml\Yaml; \
$yaml = file_get_contents('config/app.yaml'); \
Yaml::parse($yaml, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);"
// tests/Feature/YamlSecurityTest.php
public function testYamlBombProtection()
{
$bomb = str_repeat("key: ", 5000) . "value: test";
$this->expectException(\Symfony\Component\Yaml\Exception\ParseException::class);
Yaml::parse($bomb);
}
Remediation Phase:
throttle middleware:
Route::post('/parse-yaml', [YamlController::class, 'parse'])
->middleware('throttle:10,1'); // 10 requests/minute
Yaml::DUMP_OBJECT_AS_MAP to avoid deep nesting.Testing Phase:
How can I help you explore Laravel packages today?