Passed
Push — master ( 29d8e9...f4b1e7 )
by Tim
01:58
created

XMLSecurityDSig::validateReference()   A

Complexity

Conditions 6
Paths 12

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 16
c 1
b 0
f 0
nc 12
nop 0
dl 0
loc 29
rs 9.1111
1
<?php
2
3
namespace SimpleSAML\XMLSecurity;
4
5
/**
6
 * xmlseclibs.php
7
 *
8
 * Copyright (c) 2007-2017, Robert Richards <[email protected]>.
9
 * All rights reserved.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 *
15
 *   * Redistributions of source code must retain the above copyright
16
 *     notice, this list of conditions and the following disclaimer.
17
 *
18
 *   * Redistributions in binary form must reproduce the above copyright
19
 *     notice, this list of conditions and the following disclaimer in
20
 *     the documentation and/or other materials provided with the
21
 *     distribution.
22
 *
23
 *   * Neither the name of Robert Richards nor the names of his
24
 *     contributors may be used to endorse or promote products derived
25
 *     from this software without specific prior written permission.
26
 *
27
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
 * POSSIBILITY OF SUCH DAMAGE.
39
 *
40
 * @copyright 2007-2017 Robert Richards <[email protected]>
41
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
42
 */
43
44
class XMLSecurityDSig extends \RobRichards\XMLSecLibs\XMLSecurityDSig
45
{
46
    /**
47
     * @return bool
48
     * @throws Exception
49
     */
50
    public function validateReference()
51
    {
52
        $sigNode = $this->sigNode;
53
        $docElem = $sigNode->ownerDocument->documentElement;
54
55
        // enveloped signature, remove it
56
        if (!$docElem->isSameNode($sigNode)) {
0 ignored issues
show
Bug introduced by
It seems like $sigNode can also be of type null; however, parameter $otherNode of DOMNode::isSameNode() does only seem to accept DOMNode, 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 ignore-type  annotation

56
        if (!$docElem->isSameNode(/** @scrutinizer ignore-type */ $sigNode)) {
Loading history...
57
            if ($sigNode->parentNode !== null) {
58
                $sigNode->parentNode->removeChild($sigNode);
0 ignored issues
show
Bug introduced by
It seems like $sigNode can also be of type null; however, parameter $child of DOMNode::removeChild() does only seem to accept DOMNode, 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 ignore-type  annotation

58
                $sigNode->parentNode->removeChild(/** @scrutinizer ignore-type */ $sigNode);
Loading history...
59
            }
60
        }
61
        $xpath = $this->getXPathObj();
62
        $query = "./secdsig:SignedInfo[1]/secdsig:Reference";
63
        $nodeset = $xpath->query($query, $sigNode);
64
        if ($nodeset->length < 1) {
65
            throw new Exception("Reference nodes not found");
66
        }
67
68
        /* Initialize/reset the list of validated nodes. */
69
        $this->validatedNodes = [];
0 ignored issues
show
Bug introduced by
The property validatedNodes is declared private in RobRichards\XMLSecLibs\XMLSecurityDSig and cannot be accessed from this context.
Loading history...
70
71
        foreach ($nodeset as $refNode) {
72
            if (!$this->processRefNode($refNode)) {
73
                /* Clear the list of validated nodes. */
74
                $this->validatedNodes = null;
75
                throw new Exception("Reference validation failed");
76
            }
77
        }
78
        return true;
79
    }
80
}
81