Skip to content

Commit cf0ad15

Browse files
juancsjay-oswald
authored andcommitted
1 parent f1c2a29 commit cf0ad15

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

.extlib/simplesamlphp/vendor/simplesamlphp/saml2/src/SAML2/HTTPRedirect.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,36 @@ public function send(Message $message) : void
104104
public function receive(): Message
105105
{
106106
$data = self::parseQuery();
107-
if (array_key_exists('SAMLRequest', $data)) {
108-
$message = $data['SAMLRequest'];
109-
} elseif (array_key_exists('SAMLResponse', $data)) {
110-
$message = $data['SAMLResponse'];
107+
$signedQuery = $data['SignedQuery'];
108+
109+
/**
110+
* Get the SAMLRequest/SAMLResponse from the exact same signed data that will be verified later in
111+
* validateSignature into $res using the actual SignedQuery
112+
*/
113+
$res = [];
114+
foreach (explode('&', $signedQuery) as $e) {
115+
$tmp = explode('=', $e, 2);
116+
$name = $tmp[0];
117+
if (count($tmp) === 2) {
118+
$value = $tmp[1];
119+
} else {
120+
/* No value for this parameter. */
121+
$value = '';
122+
}
123+
$name = urldecode($name);
124+
$res[$name] = urldecode($value);
125+
}
126+
127+
/**
128+
* Put the SAMLRequest/SAMLResponse from the actual query string into $message,
129+
* and assert that the result from parseQuery() in $data and the parsing of the SignedQuery in $res agree
130+
*/
131+
if (array_key_exists('SAMLRequest', $res)) {
132+
Assert::same($res['SAMLRequest'], $data['SAMLRequest'], 'Parse failure.');
133+
$message = $res['SAMLRequest'];
134+
} elseif (array_key_exists('SAMLResponse', $res)) {
135+
Assert::same($res['SAMLResponse'], $data['SAMLResponse'], 'Parse failure.');
136+
$message = $res['SAMLResponse'];
111137
} else {
112138
throw new \Exception('Missing SAMLRequest or SAMLResponse parameter.');
113139
}
@@ -157,7 +183,7 @@ public function receive(): Message
157183
$signData = [
158184
'Signature' => $data['Signature'],
159185
'SigAlg' => $data['SigAlg'],
160-
'Query' => $data['SignedQuery'],
186+
'Query' => $signedQuery,
161187
];
162188

163189
$message->addValidator([get_class($this), 'validateSignature'], $signData);
@@ -196,6 +222,10 @@ private static function parseQuery() : array
196222
$value = '';
197223
}
198224
$name = urldecode($name);
225+
// Prevent keys from being set more than once
226+
if (array_key_exists($name, $data)) {
227+
throw new \Exception('Duplicate parameter.');
228+
}
199229
$data[$name] = urldecode($value);
200230

201231
switch ($name) {
@@ -211,6 +241,9 @@ private static function parseQuery() : array
211241
break;
212242
}
213243
}
244+
if (array_key_exists('SAMLRequest', $data) && array_key_exists('SAMLResponse', $data)) {
245+
throw new \Exception('Both SAMLRequest and SAMLResponse provided.');
246+
}
214247

215248
$data['SignedQuery'] = $sigQuery.$relayState.$sigAlg;
216249

0 commit comments

Comments
 (0)