You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Yaml] Bound collection-alias resolution in the parser
Track the number of resolved collection aliases (arrays, `stdClass`,
unwrapped `TaggedValue`) in the shared `ParserState`, with a default
limit of 128 — following the SnakeYAML model. Scalar aliases remain
unrestricted since they cannot drive exponential growth.
Crafted YAML documents with recursive aliases pointing at collections
that themselves contain aliases ("Billion Laughs") otherwise expand
exponentially during resolution.
Also adds `Yaml::PARSE_EXCEPTION_ON_ALIAS` to reject all aliases when
parsing untrusted input.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ CHANGELOG
5
5
---
6
6
7
7
* Add a `$maxNestingLevel` argument to `Parser::__construct()`, `Yaml::parse()` and `Yaml::parseFile()` to bound recursion depth (default 128)
8
+
* Add a `$maxAliasesForCollections` argument to `Parser::__construct()`, `Yaml::parse()` and `Yaml::parseFile()` to bound alias expansion of collection values (default 128)
9
+
* Add `Yaml::PARSE_EXCEPTION_ON_ALIAS` to reject YAML aliases while parsing untrusted input
8
10
* Add new `lint:yaml dirname --exclude=/dirname/foo.yaml --exclude=/dirname/bar.yaml`
9
11
option to exclude one or more specific files from multiple file list
10
12
* Allow negatable for the parse tags option with `--no-parse-tags`
thrownewParseException('Aliases are disabled.', $line, $snippet, $filename);
58
+
}
59
+
60
+
if ($refValueinstanceof TaggedValue) {
61
+
$refValue = $refValue->getValue();
62
+
}
63
+
64
+
if (!\is_array($refValue) && !$refValueinstanceof \stdClass) {
65
+
return;
66
+
}
67
+
68
+
if (++$this->collectionAliasCount > $this->maxAliasesForCollections) {
69
+
thrownewParseException(sprintf('Maximum number of collection aliases (%d) exceeded. This limit can be increased via the Parser constructor.', $this->maxAliasesForCollections), $line, $snippet, $filename);
0 commit comments