Issues (9)

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/Http/UrlUtil.php (1 issue)

Labels
Severity

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 sitemap-common.
4
 *
5
 * (c) 2016 Daniele Moraschi
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace SiteMap\Http;
12
13
14
class UrlUtil
15
{
16
17
    /**
18
     * @param Url $baseUrl
19
     * @param Url $url
20
     * @return bool
21
     * @throws \RuntimeException
22
     */
23
    public static function checkSameHost(Url $baseUrl, Url $url)
24
    {
25
        if ($baseUrl->getHost() == null) {
0 ignored issues
show
It seems like you are loosely comparing $baseUrl->getHost() of type string|false to null. Are you sure this is correct, and you do not want to compare to === false instead?
Loading history...
26
            throw new \RuntimeException("Base URL is null");
27
        }
28
29
        return $baseUrl->getHost() == $url->getHost();
30
    }
31
32
    /**
33
     * @param Url $baseUrl
34
     * @param $link
35
     * @return string
36
     */
37
    public static function getAbsoluteLink(Url $baseUrl, $link)
38
    {
39
        if (! $link) {
40
            return $baseUrl->getWebUrl();
41
        }
42
43
        if (self::isSingleSlashed($link)) {
44
            return self::addSchemaAndHost($baseUrl, $link);
45
        }
46
47
        if (self::isDoubleSlashed($link)) {
48
            return self::addSchema($baseUrl, $link);
49
        }
50
        
51
        if (self::isRelative($link)) {
52
            return self::buildUrl($baseUrl, $link);
53
        }
54
55
        return $link;
56
    }
57
58
    /**
59
     * @TODO Improve this, definitely not the most elegant way.
60
     * @param $link
61
     * @return bool
62
     */
63
    public static function isRelative($link)
64
    {
65
        return $link && ($link[0] === '#'
66
            || $link[0] === '?'
67
            || (strlen($link) > 3 && $link[0].$link[1].$link[2] === '../')
68
            || (strlen($link) > 2 && $link[0].$link[1] === './')
69
            || self::isPathOnly($link)
70
            || self::isSingleSlashed($link)
71
            || self::isDoubleSlashed($link));
72
    }
73
74
    /**
75
     * @param $link
76
     * @return bool
77
     */
78
    public static function isPathOnly($link)
79
    {
80
        $parts = parse_url($link);
81
        return count($parts) === 1 && isset($parts['path']);
82
    }
83
84
    /**
85
     * @param $link
86
     * @return bool
87
     */
88
    public static function isSingleSlashed($link) {
89
        return (! self::isDoubleSlashed($link)) && $link[0] === '/';
90
    }
91
92
    /**
93
     * @param $link
94
     * @return bool
95
     */
96
    public static function isDoubleSlashed($link) {
97
        return strlen($link) > 1 && $link[0].$link[1] === '//';
98
    }
99
100
    /**
101
     * @param Url $baseUrl
102
     * @param $partial
103
     * @return string
104
     */
105
    public static function buildUrl(Url $baseUrl, $partial)
106
    {
107
        return rtrim($baseUrl->getWebUrl(), '/') .'/'. ltrim($partial, '/');
108
    }
109
110
    /**
111
     * @param Url $baseUrl
112
     * @param $partial
113
     * @return string
114
     */
115
    public static function addSchema(Url $baseUrl, $partial)
116
    {
117
        return $baseUrl->getSchema() .':'. $partial;
118
    }
119
120
    /**
121
     * @param Url $baseUrl
122
     * @param $partial
123
     * @return string
124
     */
125
    public static function addSchemaAndHost(Url $baseUrl, $partial)
126
    {
127
        return $baseUrl->getSchema() .'://'. $baseUrl->getHost() .'/'. ltrim($partial, '/');
128
    }
129
}