Issues (3)

Security Analysis    not enabled

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

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
declare(strict_types=1);
4
5
namespace Arcanedev\LaravelSitemap;
6
7
use Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap;
8
use DOMDocument;
9
use Illuminate\Support\{Collection, Str};
10
11
/**
12
 * Class     SitemapBuilder
13
 *
14
 * @package  Arcanedev\LaravelSitemap
15
 * @author   ARCANEDEV <[email protected]>
16
 */
17
class SitemapBuilder
18
{
19
    /* -----------------------------------------------------------------
20
     |  Main Methods
21
     | -----------------------------------------------------------------
22
     */
23
24
    /**
25
     * Create the builder instance.
26
     *
27
     * @return \Arcanedev\LaravelSitemap\SitemapBuilder
28
     */
29 66
    public static function make()
30
    {
31 66
        return new static;
32
    }
33
34
    /**
35
     * Build the sitemap.
36
     *
37
     * @param  string|null                     $name
38
     * @param  \Illuminate\Support\Collection  $sitemaps
39
     * @param  string                          $format
40
     *
41
     * @throws \Throwable
42
     *
43
     * @return string|null
44
     */
45 66
    public function build(?string $name, Collection $sitemaps, string $format): ?string
46
    {
47 66
        if ($sitemaps->isEmpty())
48 24
            return null;
49
50 60
        if (is_null($name)) {
51 48
            return $sitemaps->count() > 1
52 36
                ? static::renderSitemapIndex($format, $sitemaps)
53 48
                : static::renderSitemap($format, $sitemaps->first());
54
        }
55
56 54
        list($name, $key) = Str::contains($name, '.')
57 6
            ? explode('.', $name, 2)
58 54
            : [$name, null];
59
60 54
        if ($sitemaps->has($name))
61 54
            return static::renderSitemap($format, $sitemaps->get($name), $key);
62
63 6
        return null;
64
    }
65
66
    /* -----------------------------------------------------------------
67
     |  Other Methods
68
     | -----------------------------------------------------------------
69
     */
70
71
    /**
72
     * Build a single sitemap item.
73
     *
74
     * @param  string                                                     $format
75
     * @param  \Arcanedev\LaravelSitemap\Contracts\Entities\Sitemap|null  $sitemap
76
     * @param  string|null                                                $key
77
     *
78
     * @throws \Throwable
79
     *
80
     * @return string|null
81
     */
82 54
    protected function renderSitemap(string $format, Sitemap $sitemap = null, string $key = null)
83
    {
84 54
        if (is_null($sitemap))
85 6
            return null;
86
87 54
        if ( ! $sitemap->isExceeded())
88 54
            return static::render($format, 'sitemap', ['sitemap' => $sitemap]);
89
90 12
        $chunks = $sitemap->chunk();
91
92 12
        if (is_null($key))
93 12
            return static::renderSitemapIndex($format, $chunks);
94
95 6
        return static::renderSitemap($format, $chunks->get($key));
96
    }
97
98
    /**
99
     * Render sitemap index.
100
     *
101
     * @param  string                          $format
102
     * @param  \Illuminate\Support\Collection  $sitemaps
103
     *
104
     * @throws \Throwable
105
     *
106
     * @return string|null
107
     */
108 48
    protected function renderSitemapIndex(string $format, Collection $sitemaps): ?string
109
    {
110 48
        return static::render($format, 'sitemap-index', compact('sitemaps'));
111
    }
112
113
    /**
114
     * Render the file.
115
     *
116
     * @param  string  $format
117
     * @param  string  $type
118
     * @param  array   $data
119
     *
120
     * @throws \Throwable
121
     *
122
     * @return string|null
123
     */
124 60
    protected function render(string $format, string $type, array $data): ?string
125
    {
126 60
        $format = strtolower(trim($format));
127
128 60
        switch ($format) {
129 60
            case 'xml':
130 30
            case 'rss':
131 42
                return static::renderXml($format, $type, $data);
132
133 24
            case 'txt':
134 18
                return static::renderView($type, $format, $data);
135
136
            default:
137 6
                return null;
138
        }
139
    }
140
141
    /**
142
     * Render the xml file.
143
     *
144
     * @param  string  $format
145
     * @param  string  $type
146
     * @param  array   $data
147
     *
148
     * @return string
149
     */
150 42
    protected function renderXml(string $format, string $type, array $data): string
151
    {
152
        return tap(new DOMDocument('1.0'), function (DOMDocument $document) use ($format, $type, $data) {
153 42
            $document->preserveWhiteSpace = false;
154 42
            $document->formatOutput = true;
155 42
            $document->loadXML(
156 42
                static::renderView($type, $format, $data)
157
            );
158 42
        })->saveXML();
159
    }
160
161
    /**
162
     * Render with illuminate.
163
     *
164
     * @param  string  $type
165
     * @param  string  $format
166
     * @param  array   $data
167
     *
168
     * @throws \Throwable
169
     *
170
     * @return string
171
     */
172 54
    protected function renderView(string $type, string $format, array $data): string
173
    {
174 54
        return view("sitemap::{$type}.{$format}", $data)->render();
0 ignored issues
show
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
175
    }
176
}
177