Issues (2)

Security Analysis    no request data  

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

  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.
  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.
  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.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  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.
  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.
  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.
  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.
  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.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  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.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
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/Urn.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This file is part of the Urn project
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Urn;
9
10
/**
11
 * URN class.
12
 *
13
 * @package GravityMedia\Urn
14
 */
15
class Urn implements UrnInterface
16
{
17
    /**
18
     * Namespace identifier regex pattern.
19
     *
20
     * @const string
21
     */
22
    const NID_PATTERN = '/^[A-Za-z0-9-][A-Za-z0-9-]{0,31}$/';
23
24
    /**
25
     * Namespace specific string regex pattern.
26
     */
27
    const NSS_PATTERN = '/^[A-Za-z0-9()+,\-.:=@;$_!*\'%\/?#]+$/';
28
29
    /**
30
     * The namespace identifier.
31
     *
32
     * @var string
33
     */
34
    protected $namespaceIdentifier;
35
36
    /**
37
     * The namespace specific string.
38
     *
39
     * @var string
40
     */
41
    protected $namespaceSpecificString;
42
43
    /**
44
     * The protected constructor.
45
     */
46 4
    protected function __construct()
47
    {
48
        // to prevent object construction without nid and/or nss
49 4
    }
50
51
    /**
52
     * Create URN object from array.
53
     *
54
     * @param array $array
55
     *
56
     * @return static
57
     * @throws \InvalidArgumentException
58
     */
59 4
    public static function fromArray(array $array)
60
    {
61 4
        if (!isset($array['nid'])) {
62
            throw new \InvalidArgumentException('The namespace identifier was not specified');
63
        }
64
65 4
        if (!isset($array['nss'])) {
66
            throw new \InvalidArgumentException('The namespace specific string was not specified');
67
        }
68
69
        /** @var Urn $urn */
70 4
        $urn = new static();
71 4
        $urn = $urn->withNamespaceIdentifier($array['nid']);
72 4
        $urn = $urn->withNamespaceSpecificString($array['nss']);
73
74 4
        return $urn;
75
    }
76
77
    /**
78
     * Create URN object from string.
79
     *
80
     * @param string $string
81
     *
82
     * @return static
83
     * @throws \InvalidArgumentException
84
     */
85 6
    public static function fromString($string)
86
    {
87 6
        $array = explode(':', $string, 3);
88 6
        if (3 !== count($array) || 'urn' !== strtolower($array[0])) {
89 2
            throw new \InvalidArgumentException('The string argument appears to be malformed');
90
        }
91
92 4
        if (1 !== preg_match(static::NID_PATTERN, $array[1])) {
93
            throw new \InvalidArgumentException('The string does not contain a valid namespace identifier');
94
        }
95
96 4
        if (1 !== preg_match(static::NSS_PATTERN, $array[2])) {
97
            throw new \InvalidArgumentException('The string does not contain a valid namespace specific string');
98
        }
99
100 4
        $array['nid'] = $array[1];
101 4
        $array['nss'] = $array[2];
102
103 4
        return static::fromArray($array);
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109 4
    public function getNamespaceIdentifier()
110
    {
111 4
        return $this->namespaceIdentifier;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117 4
    public function getNamespaceSpecificString()
118
    {
119 4
        return $this->namespaceSpecificString;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125 4 View Code Duplication
    public function withNamespaceIdentifier($nid)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
    {
127 4
        if (1 !== preg_match(static::NID_PATTERN, $nid)) {
128
            throw new \InvalidArgumentException('The string does not contain a valid namespace identifier');
129
        }
130
131 4
        $urn = clone $this;
132 4
        $urn->namespaceIdentifier = (string)$nid;
133
134 4
        return $urn;
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140 4 View Code Duplication
    public function withNamespaceSpecificString($nss)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
    {
142 4
        if (1 !== preg_match(static::NSS_PATTERN, $nss)) {
143
            throw new \InvalidArgumentException('The string does not contain a valid namespace specific string');
144
        }
145
146 4
        $urn = clone $this;
147 4
        $urn->namespaceSpecificString = (string)$nss;
148
149 4
        return $urn;
150
    }
151
152
    /**
153
     * {@inheritdoc}
154
     */
155 4
    public function __toString()
156
    {
157 4
        return $this->toString();
158
    }
159
160
    /**
161
     * Convert URN into a string representation.
162
     *
163
     * @return string
164
     */
165 4
    public function toString()
166
    {
167 4
        $urn = 'urn';
168 4
        $urn .= ':' . $this->getNamespaceIdentifier();
169 4
        $urn .= ':' . $this->getNamespaceSpecificString();
170
171 4
        return $urn;
172
    }
173
}
174