simplesamlphp /
saml2
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace SimpleSAML\SAML2\XML\samlp; |
||||
| 6 | |||||
| 7 | use DOMElement; |
||||
| 8 | use SimpleSAML\SAML2\Assert\Assert; |
||||
| 9 | use SimpleSAML\SAML2\Constants as C; |
||||
| 10 | use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooHighException; |
||||
| 11 | use SimpleSAML\SAML2\Exception\Protocol\RequestVersionTooLowException; |
||||
| 12 | use SimpleSAML\SAML2\Type\SAMLAnyURIValue; |
||||
| 13 | use SimpleSAML\SAML2\Type\SAMLDateTimeValue; |
||||
| 14 | use SimpleSAML\SAML2\Type\SAMLStringValue; |
||||
| 15 | use SimpleSAML\SAML2\XML\IdentifierTrait; |
||||
| 16 | use SimpleSAML\SAML2\XML\saml\AbstractBaseID; |
||||
| 17 | use SimpleSAML\SAML2\XML\saml\EncryptedID; |
||||
| 18 | use SimpleSAML\SAML2\XML\saml\IdentifierInterface; |
||||
| 19 | use SimpleSAML\SAML2\XML\saml\Issuer; |
||||
| 20 | use SimpleSAML\SAML2\XML\saml\NameID; |
||||
| 21 | use SimpleSAML\XML\SchemaValidatableElementInterface; |
||||
| 22 | use SimpleSAML\XML\SchemaValidatableElementTrait; |
||||
| 23 | use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException; |
||||
| 24 | use SimpleSAML\XMLSchema\Exception\MissingElementException; |
||||
| 25 | use SimpleSAML\XMLSchema\Exception\TooManyElementsException; |
||||
| 26 | use SimpleSAML\XMLSchema\Type\IDValue; |
||||
| 27 | use SimpleSAML\XMLSecurity\XML\ds\Signature; |
||||
| 28 | |||||
| 29 | use function array_pop; |
||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * Class for SAML 2 logout request messages. |
||||
| 33 | * |
||||
| 34 | * @package simplesamlphp/saml2 |
||||
| 35 | */ |
||||
| 36 | final class LogoutRequest extends AbstractRequest implements SchemaValidatableElementInterface |
||||
| 37 | { |
||||
| 38 | use IdentifierTrait; |
||||
| 39 | use SchemaValidatableElementTrait; |
||||
| 40 | |||||
| 41 | |||||
| 42 | /** |
||||
| 43 | * Constructor for SAML 2 AttributeQuery. |
||||
| 44 | * |
||||
| 45 | * @param \SimpleSAML\XMLSchema\Type\IDValue $id |
||||
| 46 | * @param \SimpleSAML\SAML2\XML\saml\IdentifierInterface $identifier |
||||
| 47 | * @param \SimpleSAML\SAML2\Type\SAMLDateTimeValue $issueInstant |
||||
| 48 | * @param \SimpleSAML\SAML2\Type\SAMLDateTimeValue|null $notOnOrAfter |
||||
| 49 | * @param \SimpleSAML\SAML2\Type\SAMLStringValue|null $reason |
||||
| 50 | * @param \SimpleSAML\SAML2\XML\samlp\SessionIndex[] $sessionIndexes |
||||
| 51 | * @param \SimpleSAML\SAML2\XML\saml\Issuer|null $issuer |
||||
| 52 | * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $destination |
||||
| 53 | * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $consent |
||||
| 54 | * @param \SimpleSAML\SAML2\XML\samlp\Extensions $extensions |
||||
| 55 | * @throws \Exception |
||||
| 56 | */ |
||||
| 57 | public function __construct( |
||||
| 58 | IDValue $id, |
||||
| 59 | IdentifierInterface $identifier, |
||||
| 60 | SAMLDateTimeValue $issueInstant, |
||||
| 61 | protected ?SAMLDateTimeValue $notOnOrAfter = null, |
||||
| 62 | protected ?SAMLStringValue $reason = null, |
||||
| 63 | protected array $sessionIndexes = [], |
||||
| 64 | ?Issuer $issuer = null, |
||||
| 65 | ?SAMLAnyURIValue $destination = null, |
||||
| 66 | ?SAMLAnyURIValue $consent = null, |
||||
| 67 | ?Extensions $extensions = null, |
||||
| 68 | ) { |
||||
| 69 | Assert::maxCount($sessionIndexes, C::UNBOUNDED_LIMIT); |
||||
| 70 | Assert::allIsInstanceOf($sessionIndexes, SessionIndex::class); |
||||
| 71 | |||||
| 72 | parent::__construct($id, $issuer, $issueInstant, $destination, $consent, $extensions); |
||||
| 73 | |||||
| 74 | $this->setIdentifier($identifier); |
||||
| 75 | } |
||||
| 76 | |||||
| 77 | |||||
| 78 | /** |
||||
| 79 | * Retrieve the expiration time of this request. |
||||
| 80 | * |
||||
| 81 | * @return \SimpleSAML\SAML2\Type\SAMLDateTimeValue|null The expiration time of this request. |
||||
| 82 | */ |
||||
| 83 | public function getNotOnOrAfter(): ?SAMLDateTimeValue |
||||
| 84 | { |
||||
| 85 | return $this->notOnOrAfter; |
||||
| 86 | } |
||||
| 87 | |||||
| 88 | |||||
| 89 | /** |
||||
| 90 | * Retrieve the reason for this request. |
||||
| 91 | * |
||||
| 92 | * @return \SimpleSAML\SAML2\Type\SAMLStringValue|null The reason for this request. |
||||
| 93 | */ |
||||
| 94 | public function getReason(): ?SAMLStringValue |
||||
| 95 | { |
||||
| 96 | return $this->reason; |
||||
| 97 | } |
||||
| 98 | |||||
| 99 | |||||
| 100 | /** |
||||
| 101 | * Retrieve the SessionIndexes of the sessions that should be terminated. |
||||
| 102 | * |
||||
| 103 | * @return \SimpleSAML\SAML2\XML\samlp\SessionIndex[] |
||||
| 104 | * The SessionIndexes, or an empty array if all sessions should be terminated. |
||||
| 105 | */ |
||||
| 106 | public function getSessionIndexes(): array |
||||
| 107 | { |
||||
| 108 | return $this->sessionIndexes; |
||||
| 109 | } |
||||
| 110 | |||||
| 111 | |||||
| 112 | /** |
||||
| 113 | * Convert XML into a LogoutRequest |
||||
| 114 | * |
||||
| 115 | * @param \DOMElement $xml The XML element we should load |
||||
| 116 | * @return static |
||||
| 117 | * |
||||
| 118 | * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException |
||||
| 119 | * if the qualified name of the supplied element is wrong |
||||
| 120 | * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException |
||||
| 121 | * if the supplied element is missing one of the mandatory attributes |
||||
| 122 | * @throws \SimpleSAML\XMLSchema\Exception\MissingElementException |
||||
| 123 | * if one of the mandatory child-elements is missing |
||||
| 124 | * @throws \SimpleSAML\XMLSchema\Exception\TooManyElementsException |
||||
| 125 | * if too many child-elements of a type are specified |
||||
| 126 | */ |
||||
| 127 | public static function fromXML(DOMElement $xml): static |
||||
| 128 | { |
||||
| 129 | Assert::same($xml->localName, 'LogoutRequest', InvalidDOMElementException::class); |
||||
| 130 | Assert::same($xml->namespaceURI, LogoutRequest::NS, InvalidDOMElementException::class); |
||||
| 131 | |||||
| 132 | $version = self::getAttribute($xml, 'Version', SAMLStringValue::class); |
||||
| 133 | Assert::true(version_compare('2.0', strval($version), '<='), RequestVersionTooLowException::class); |
||||
| 134 | Assert::true(version_compare('2.0', strval($version), '>='), RequestVersionTooHighException::class); |
||||
| 135 | |||||
| 136 | $id = self::getAttribute($xml, 'ID', IDValue::Class); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 137 | $issueInstant = self::getAttribute($xml, 'IssueInstant', SAMLDateTimeValue::class); |
||||
| 138 | |||||
| 139 | $notOnOrAfter = self::getOptionalAttribute($xml, 'NotOnOrAfter', SAMLDateTimeValue::class, null); |
||||
| 140 | |||||
| 141 | $issuer = Issuer::getChildrenOfClass($xml); |
||||
| 142 | Assert::countBetween($issuer, 0, 1); |
||||
| 143 | |||||
| 144 | $extensions = Extensions::getChildrenOfClass($xml); |
||||
| 145 | Assert::maxCount( |
||||
| 146 | $extensions, |
||||
| 147 | 1, |
||||
| 148 | 'Only one saml:Extensions element is allowed.', |
||||
| 149 | TooManyElementsException::class, |
||||
| 150 | ); |
||||
| 151 | |||||
| 152 | $identifier = self::getIdentifierFromXML($xml); |
||||
| 153 | Assert::notNull( |
||||
| 154 | $identifier, |
||||
| 155 | 'Missing <saml:NameID>, <saml:BaseID> or <saml:EncryptedID> in <samlp:LogoutRequest>.', |
||||
| 156 | MissingElementException::class, |
||||
| 157 | ); |
||||
| 158 | Assert::isInstanceOfAny($identifier, [AbstractBaseID::class, NameID::class, EncryptedID::class]); |
||||
| 159 | |||||
| 160 | $signature = Signature::getChildrenOfClass($xml); |
||||
| 161 | Assert::maxCount($signature, 1, 'Only one ds:Signature element is allowed.'); |
||||
| 162 | |||||
| 163 | $sessionIndex = SessionIndex::getChildrenOfClass($xml); |
||||
| 164 | |||||
| 165 | $request = new static( |
||||
| 166 | $id, |
||||
|
0 ignored issues
–
show
$id of type SimpleSAML\XMLSchema\Type\QNameValue is incompatible with the type SimpleSAML\XMLSchema\Type\IDValue expected by parameter $id of SimpleSAML\SAML2\XML\sam...tRequest::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 167 | $identifier, |
||||
|
0 ignored issues
–
show
It seems like
$identifier can also be of type null; however, parameter $identifier of SimpleSAML\SAML2\XML\sam...tRequest::__construct() does only seem to accept SimpleSAML\SAML2\XML\saml\IdentifierInterface, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 168 | $issueInstant, |
||||
| 169 | $notOnOrAfter, |
||||
| 170 | self::getOptionalAttribute($xml, 'Reason', SAMLStringValue::class, null), |
||||
| 171 | $sessionIndex, |
||||
| 172 | array_pop($issuer), |
||||
| 173 | self::getOptionalAttribute($xml, 'Destination', SAMLAnyURIValue::class, null), |
||||
| 174 | self::getOptionalAttribute($xml, 'Consent', SAMLAnyURIValue::class, null), |
||||
| 175 | array_pop($extensions), |
||||
| 176 | ); |
||||
| 177 | |||||
| 178 | if (!empty($signature)) { |
||||
| 179 | $request->setSignature($signature[0]); |
||||
| 180 | $request->messageContainedSignatureUponConstruction = true; |
||||
| 181 | $request->setXML($xml); |
||||
| 182 | } |
||||
| 183 | |||||
| 184 | return $request; |
||||
| 185 | } |
||||
| 186 | |||||
| 187 | |||||
| 188 | /** |
||||
| 189 | * Convert this message to an unsigned XML document. |
||||
| 190 | * This method does not sign the resulting XML document. |
||||
| 191 | * |
||||
| 192 | * @return \DOMElement The root element of the DOM tree |
||||
| 193 | */ |
||||
| 194 | protected function toUnsignedXML(?DOMElement $parent = null): DOMElement |
||||
| 195 | { |
||||
| 196 | $e = parent::toUnsignedXML($parent); |
||||
| 197 | |||||
| 198 | if ($this->getNotOnOrAfter() !== null) { |
||||
| 199 | $e->setAttribute('NotOnOrAfter', $this->getNotOnOrAfter()->getValue()); |
||||
| 200 | } |
||||
| 201 | |||||
| 202 | if ($this->getReason() !== null) { |
||||
| 203 | $e->setAttribute('Reason', $this->getReason()->getValue()); |
||||
| 204 | } |
||||
| 205 | |||||
| 206 | /** @var \SimpleSAML\XML\SerializableElementInterface&\SimpleSAML\SAML2\XML\saml\IdentifierInterface $identifier */ |
||||
| 207 | $identifier = $this->getIdentifier(); |
||||
| 208 | $identifier->toXML($e); |
||||
| 209 | |||||
| 210 | foreach ($this->getSessionIndexes() as $sessionIndex) { |
||||
| 211 | $sessionIndex->toXML($e); |
||||
| 212 | } |
||||
| 213 | |||||
| 214 | return $e; |
||||
| 215 | } |
||||
| 216 | } |
||||
| 217 |