@@ -743,6 +743,10 @@ protected static function buildWithBaseURLPath($info)
743743 */
744744 public static function extractOriginalQueryParam ($ name )
745745 {
746+ if (!isset ($ _SERVER ['QUERY_STRING ' ]) || empty ($ _SERVER ['QUERY_STRING ' ])) {
747+ return '' ;
748+ }
749+
746750 $ index = strpos ($ _SERVER ['QUERY_STRING ' ], $ name .'= ' );
747751 $ substring = substr ($ _SERVER ['QUERY_STRING ' ], $ index + strlen ($ name ) + 1 );
748752 $ end = strpos ($ substring , '& ' );
@@ -1541,13 +1545,43 @@ public static function validateBinarySign($messageType, $getData, $idpData, $ret
15411545 $ signAlg = $ getData ['SigAlg ' ];
15421546 }
15431547
1548+
15441549 if ($ retrieveParametersFromServer ) {
1550+ if (!isset ($ _SERVER ['QUERY_STRING ' ]) || empty ($ _SERVER ['QUERY_STRING ' ])) {
1551+ throw new Error (
1552+ "No query string provided " ,
1553+ Error::INVALID_PARAMETER
1554+ );
1555+ }
1556+ $ keys = ["SAMLRequest " , "SAMLResponse " , "RelayState " , "SigAlg " , "Signature " ];
1557+ foreach ($ keys as $ key ) {
1558+ if (substr_count ($ _SERVER ['QUERY_STRING ' ], $ key ) > 1 ) {
1559+ throw new Error (
1560+ "Duplicate parameter in query string " ,
1561+ Error::INVALID_PARAMETER
1562+ );
1563+ }
1564+ }
1565+ if (substr_count ($ _SERVER ['QUERY_STRING ' ], "SAMLRequest " ) > 0 && substr_count ($ _SERVER ['QUERY_STRING ' ], "SAMLResponse " ) > 0 ) {
1566+ throw new Error (
1567+ "Both SAMLRequest and SAMLResponse provided " ,
1568+ Error::INVALID_PARAMETER
1569+ );
1570+ }
1571+
15451572 $ signedQuery = $ messageType .'= ' .Utils::extractOriginalQueryParam ($ messageType );
15461573 if (isset ($ getData ['RelayState ' ])) {
15471574 $ signedQuery .= '&RelayState= ' .Utils::extractOriginalQueryParam ('RelayState ' );
15481575 }
15491576 $ signedQuery .= '&SigAlg= ' .Utils::extractOriginalQueryParam ('SigAlg ' );
15501577 } else {
1578+ if (isset ($ getData ['SAMLRequest ' ]) && isset ($ getData ['SAMLResponse ' ])) {
1579+ throw new Error (
1580+ "Both SAMLRequest and SAMLResponse provided " ,
1581+ Error::INVALID_PARAMETER
1582+ );
1583+ }
1584+
15511585 $ signedQuery = $ messageType .'= ' .urlencode ($ getData [$ messageType ]);
15521586 if (isset ($ getData ['RelayState ' ])) {
15531587 $ signedQuery .= '&RelayState= ' .urlencode ($ getData ['RelayState ' ]);
0 commit comments