Skip to content

Commit 7f7f5c5

Browse files
committed
Add assertions to prevent denial of service
1 parent 8e16309 commit 7f7f5c5

File tree

8 files changed

+17
-0
lines changed

8 files changed

+17
-0
lines changed

src/XMLSchema/XML/xs/AbstractElement.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DOMElement;
88
use SimpleSAML\XML\Assert\Assert;
9+
use SimpleSAML\XML\Constants as C;
910
use SimpleSAML\XMLSchema\Exception\{ProtocolViolationException, SchemaViolationException};
1011
use SimpleSAML\XMLSchema\Type\Builtin\{BooleanValue, IDValue, NCNameValue, QNameValue, StringValue};
1112
use SimpleSAML\XMLSchema\Type\{BlockSetValue, DerivationSetValue, FormChoiceValue, MaxOccursValue, MinOccursValue};
@@ -64,6 +65,7 @@ public function __construct(
6465
?IDValue $id = null,
6566
array $namespacedAttributes = [],
6667
) {
68+
Assert::maxCount($identityConstraint, C::UNBOUNDED_LIMIT);
6769
Assert::allIsInstanceOf(
6870
$identityConstraint,
6971
IdentityConstraintInterface::class,

src/XMLSchema/XML/xs/AbstractGroup.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace SimpleSAML\XMLSchema\XML\xs;
66

77
use DOMElement;
8+
use SimpleSAML\XML\Assert\Assert;
9+
use SimpleSAML\XML\Constants as C;
810
use SimpleSAML\XMLSchema\Type\Builtin\{IDValue, NCNameValue, QNameValue};
911
use SimpleSAML\XMLSchema\Type\{MinOccursValue, MaxOccursValue};
1012

@@ -42,6 +44,8 @@ public function __construct(
4244
?IDValue $id = null,
4345
array $namespacedAttributes = [],
4446
) {
47+
Assert::maxCount($particles, C::UNBOUNDED_LIMIT);
48+
4549
parent::__construct($annotation, $id, $namespacedAttributes);
4650

4751
$this->setName($name);

src/XMLSchema/XML/xs/AbstractKeybase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DOMElement;
88
use SimpleSAML\XML\Assert\Assert;
9+
use SimpleSAML\XML\Constants as C;
910
use SimpleSAML\XMLSchema\Exception\MissingElementException;
1011
use SimpleSAML\XMLSchema\Type\Builtin\{IDValue, NCNameValue};
1112

@@ -36,6 +37,7 @@ public function __construct(
3637
protected ?IDValue $id = null,
3738
array $namespacedAttributes = [],
3839
) {
40+
Assert::maxCount($field, C::UNBOUNDED_LIMIT);
3941
Assert::allIsInstanceOf($field, Field::class, MissingElementException::class);
4042

4143
parent::__construct($annotation, $id, $namespacedAttributes);

src/XMLSchema/XML/xs/AttrDeclsTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SimpleSAML\XMLSchema\XML\xs;
66

77
use SimpleSAML\XML\Assert\Assert;
8+
use SimpleSAML\XML\Constants as C;
89
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
910

1011
/**
@@ -67,6 +68,7 @@ public function getAnyAttribute(): ?AnyAttribute
6768
*/
6869
protected function setAttributes(array $attributes): void
6970
{
71+
Assert::maxCount($attributes, C::UNBOUNDED_LIMIT);
7072
Assert::allIsInstanceOfAny(
7173
$attributes,
7274
[LocalAttribute::class, ReferencedAttributeGroup::class],

src/XMLSchema/XML/xs/Documentation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ final public function __construct(
5353
protected ?AnyURIValue $source = null,
5454
array $namespacedAttributes = [],
5555
) {
56+
Assert::lessThanEq($content->count(), C::UNBOUNDED_LIMIT);
5657
$this->setAttributesNS($namespacedAttributes);
5758
}
5859

src/XMLSchema/XML/xs/Redefine.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function __construct(
4242
protected array $redefineElements = [],
4343
array $namespacedAttributes = [],
4444
) {
45+
Assert::maxCount($redefineElements, C::UNBOUNDED_LIMIT);
4546
Assert::allIsInstanceOfAny(
4647
$redefineElements,
4748
[RedefinableInterface::class, Annotation::class],

src/XMLSchema/XML/xs/Schema.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@ public function __construct(
7777
protected ?XMLAttribute $lang = null,
7878
array $namespacedAttributes = [],
7979
) {
80+
Assert::maxCount($topLevelElements, C::UNBOUNDED_LIMIT);
8081
Assert::allIsInstanceOfAny(
8182
$topLevelElements,
8283
[XsInclude::class, Import::class, Redefine::class, Annotation::class],
8384
SchemaViolationException::class,
8485
);
86+
87+
Assert::maxCount($schemaTopElements, C::UNBOUNDED_LIMIT);
8588
Assert::allIsInstanceOfAny(
8689
$schemaTopElements,
8790
[

src/XMLSchema/XML/xs/Union.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DOMElement;
88
use SimpleSAML\XML\Assert\Assert;
9+
use SimpleSAML\XML\Constants as C;
910
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
1011
use SimpleSAML\XMLSchema\Exception\{
1112
InvalidDOMElementException,
@@ -55,6 +56,7 @@ public function __construct(
5556
Assert::allIsInstanceOf($simpleType, LocalSimpleType::class, SchemaViolationException::class);
5657
Assert::allIsInstanceOf($memberTypes, QNameValue::class, SchemaViolationException::class);
5758

59+
Assert::maxCount($memberTypes, C::UNBOUNDED_LIMIT);
5860
if (empty($memberTypes)) {
5961
Assert::minCount($simpleType, 1, MissingElementException::class);
6062
}

0 commit comments

Comments
 (0)