Issues (538)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  Header Injection
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/XML/saml/Attribute.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\saml;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Constants as C;
10
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
11
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
12
use SimpleSAML\SAML2\Type\SAMLStringValue;
13
use SimpleSAML\SAML2\XML\EncryptableElementTrait;
14
use SimpleSAML\XML\ExtendableAttributesTrait;
15
use SimpleSAML\XML\SchemaValidatableElementInterface;
16
use SimpleSAML\XML\SchemaValidatableElementTrait;
17
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
18
use SimpleSAML\XMLSchema\XML\Constants\NS;
19
use SimpleSAML\XMLSecurity\Backend\EncryptionBackend;
20
use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface;
21
22
use function array_unique;
23
use function count;
24
use function strval;
25
26
/**
27
 * Class representing SAML 2 Attribute.
28
 *
29
 * @package simplesamlphp/saml2
30
 */
31
class Attribute extends AbstractSamlElement implements
32
    EncryptableElementInterface,
33
    SchemaValidatableElementInterface
34
{
35
    use EncryptableElementTrait;
36
    use ExtendableAttributesTrait;
37
    use SchemaValidatableElementTrait;
38
39
40
    /** The namespace-attribute for the xs:anyAttribute element */
41
    public const string XS_ANY_ATTR_NAMESPACE = NS::OTHER;
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 41 at column 24
Loading history...
42
43
    /**
44
     * The exclusions for the xs:anyAttribute element
45
     *
46
     * @var array<int, array<int, string>>
47
     */
48
    public const array XS_ANY_ATTR_EXCLUSIONS = [
49
        ['urn:oasis:names:tc:SAML:2.0:assertion', '*'],
50
        ['urn:oasis:names:tc:SAML:2.0:metadata', '*'],
51
        ['urn:oasis:names:tc:SAML:2.0:protocol', '*'],
52
    ];
53
54
55
    /**
56
     * Initialize an Attribute.
57
     *
58
     * @param \SimpleSAML\SAML2\Type\SAMLStringValue $name
59
     * @param \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null $nameFormat
60
     * @param \SimpleSAML\SAML2\Type\SAMLStringValue|null $friendlyName
61
     * @param \SimpleSAML\SAML2\XML\saml\AttributeValue[] $attributeValue
62
     * @param \SimpleSAML\XML\Attribute[] $namespacedAttribute
63
     */
64
    public function __construct(
65
        protected SAMLStringValue $name,
66
        protected ?SAMLAnyURIValue $nameFormat = null,
67
        protected ?SAMLStringValue $friendlyName = null,
68
        protected array $attributeValue = [],
69
        array $namespacedAttribute = [],
70
    ) {
71
        Assert::maxCount($attributeValue, C::UNBOUNDED_LIMIT);
72
        Assert::allIsInstanceOf($attributeValue, AttributeValue::class, InvalidDOMElementException::class);
73
74
        switch (strval($nameFormat)) {
75
            case C::NAMEFORMAT_URI:
76
                Assert::validURI(
77
                    strval($name),
78
                    sprintf("Attribute name `%s` does not match its declared format `%s`", $name, $nameFormat),
79
                );
80
                break;
81
            case C::NAMEFORMAT_BASIC:
82
                Assert::validNCName(
83
                    strval($name),
84
                    sprintf("Attribute name `%s` does not match its declared format `%s`", $name, $nameFormat),
85
                );
86
                break;
87
        }
88
89
        $types = array_map(
90
            function (AttributeValue $av) {
91
                return $av->getXsiType();
92
            },
93
            $attributeValue,
94
        );
95
96
        if ($types !== []) {
97
            Assert::same(
98
                count(array_unique($types)),
99
                1,
100
                "All of the <AttributeValue> elements must have the identical datatype assigned.",
101
                ProtocolViolationException::class,
102
            );
103
        }
104
105
        $this->setAttributesNS($namespacedAttribute);
106
    }
107
108
109
    /**
110
     * Collect the value of the Name-property
111
     *
112
     * @return \SimpleSAML\SAML2\Type\SAMLStringValue
113
     */
114
    public function getName(): SAMLStringValue
115
    {
116
        return $this->name;
117
    }
118
119
120
    /**
121
     * Collect the value of the NameFormat-property
122
     *
123
     * @return \SimpleSAML\SAML2\Type\SAMLAnyURIValue|null
124
     */
125
    public function getNameFormat(): ?SAMLAnyURIValue
126
    {
127
        return $this->nameFormat;
128
    }
129
130
131
    /**
132
     * Collect the value of the FriendlyName-property
133
     *
134
     * @return \SimpleSAML\SAML2\Type\SAMLStringValue|null
135
     */
136
    public function getFriendlyName(): ?SAMLStringValue
137
    {
138
        return $this->friendlyName;
139
    }
140
141
142
    /**
143
     * Collect the value of the attributeValues-property
144
     *
145
     * @return \SimpleSAML\SAML2\XML\saml\AttributeValue[]
146
     */
147
    public function getAttributeValues(): array
148
    {
149
        return $this->attributeValue;
150
    }
151
152
153
    /**
154
     * @return \SimpleSAML\XMLSecurity\Backend\EncryptionBackend|null
155
     */
156
    public function getEncryptionBackend(): ?EncryptionBackend
157
    {
158
        // return the encryption backend you want to use,
159
        // or null if you are fine with the default
160
        return null;
161
    }
162
163
164
    /**
165
     * Convert XML into a Attribute
166
     *
167
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
168
     *   if the qualified name of the supplied element is wrong
169
     * @throws \SimpleSAML\XMLSchema\Exception\MissingAttributeException
170
     *   if the supplied element is missing one of the mandatory attributes
171
     */
172
    public static function fromXML(DOMElement $xml): static
173
    {
174
        Assert::same($xml->localName, 'Attribute', InvalidDOMElementException::class);
175
        Assert::same($xml->namespaceURI, Attribute::NS, InvalidDOMElementException::class);
176
177
        return new static(
178
            self::getAttribute($xml, 'Name', SAMLStringValue::class),
179
            self::getOptionalAttribute($xml, 'NameFormat', SAMLAnyURIValue::class, null),
180
            self::getOptionalAttribute($xml, 'FriendlyName', SAMLStringValue::class, null),
181
            AttributeValue::getChildrenOfClass($xml),
182
            self::getAttributesNSFromXML($xml),
183
        );
184
    }
185
186
187
    /**
188
     * Convert this Attribute to XML.
189
     */
190
    public function toXML(?DOMElement $parent = null): DOMElement
191
    {
192
        $e = $this->instantiateParentElement($parent);
193
        $e->setAttribute('Name', strval($this->getName()));
194
195
        if ($this->getNameFormat() !== null) {
196
            $e->setAttribute('NameFormat', strval($this->getNameFormat()));
197
        }
198
199
        if ($this->getFriendlyName() !== null) {
200
            $e->setAttribute('FriendlyName', strval($this->getFriendlyName()));
201
        }
202
203
        foreach ($this->getAttributesNS() as $attr) {
204
            $attr->toXML($e);
205
        }
206
207
        foreach ($this->getAttributeValues() as $av) {
208
            $av->toXML($e);
209
        }
210
211
        return $e;
212
    }
213
}
214