Issues (4)

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/LaravelPages.php (4 issues)

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
namespace JeroenG\LaravelPages;
4
5
/**
6
 * This class is the core of the package. Everything is handles through here, although you might always use the Facade 'LPages'.
7
 *
8
 * @author 	JeroenG
9
 **/
10
class LaravelPages
11
{
12
    /**
13
     * Checks if a page exists in the database.
14
     *
15
     * @param string $slug The slug to search for in the database.
16
     * @return bool Returns true if the page exists, false otherwise.
17
     **/
18
    public function pageExists($slug)
19
    {
20
        $count = Page::where('page_slug', '=', $slug)->count();
21
22
        if ($count == 0) {
23
            return false;
24
        } else {
25
            return true;
26
        }
27
    }
28
29
    /**
30
     * Gets all the data of the page from the database, based on the slug.
31
     *
32
     * @param string $slug The slug to search for in the database.
33
     * @param bool $trashed Include trashed (soft deleted) pages?
34
     * @return array The data such as title, content and publishing date in an array.
35
     **/
36
    public function getPage($slug, $trashed = false)
37
    {
38
        if ($trashed) {
39
            return Page::withTrashed()->where('page_slug', '=', $slug)->first();
40
        }
41
42
        return Page::where('page_slug', '=', $slug)->first();
43
    }
44
45
    /**
46
     * Gets all the data of the page from the database, based on the ID.
47
     *
48
     * @param string $id The id to search for in the database.
49
     * @param bool $trashed Include trashed (soft deleted) pages?
50
     * @return array The data such as title, content and publishing date in an array.
51
     **/
52
    public function getPageById($id, $trashed = false)
53
    {
54
        if ($trashed) {
55
            return Page::withTrashed()->find($id);
56
        }
57
58
        return Page::find($id);
59
    }
60
61
    /**
62
     * Gets only the id of the page that belongs to the given slug.
63
     *
64
     * @param string $slug The slug to search for in the database.
65
     * @return int The id of the page.
66
     **/
67
    public function getPageId($slug)
68
    {
69
        $query = Page::where('page_slug', '=', $slug)->withTrashed()->select('page_id')->first();
70
71
        return $query->page_id;
72
    }
73
74
    /**
75
     * Creates a slug.
76
     *
77
     * @param string $slugify_this The piece of text to transform into a slug.
78
     * @return string A safe slug.
79
     **/
80
    public function createSlug($slugify_this)
81
    {
82
        return str_slug($slugify_this);
83
    }
84
85
    /**
86
     * Adds a page to the database.
87
     *
88
     * @param string $page_title The title of the page.
89
     * @param text $page_content The content of the page.
90
     * @param string|null $custom_slug A custom slug, if not provided the page title is slugified.
91
     * @return void The page is saved.
92
     **/
93
    public function addPage($page_title, $page_content, $custom_slug = null)
94
    {
95
        $newPage = new Page;
96
        $newPage->page_title = $page_title;
0 ignored issues
show
The property page_title does not exist on object<JeroenG\LaravelPages\Page>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
97
        $newPage->page_content = $page_content;
0 ignored issues
show
The property page_content does not exist on object<JeroenG\LaravelPages\Page>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
98
        if (is_null($custom_slug) or empty($custom_slug)) {
99
            $newPage->page_slug = $this->createSlug($page_title);
0 ignored issues
show
The property page_slug does not exist on object<JeroenG\LaravelPages\Page>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
100
        } else {
101
            $newPage->page_slug = $this->createSlug($custom_slug);
0 ignored issues
show
The property page_slug does not exist on object<JeroenG\LaravelPages\Page>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
102
        }
103
104
        return $newPage->save();
105
    }
106
107
    /**
108
     * Updates an existing page.
109
     *
110
     * @param int $page_id The id of the existing page.
111
     * @param string $page_title The (changed) title of the page.
112
     * @param text $page_content The (changed) content of the page.
113
     * @param string $page_slug The (changed) slug of the page.
114
     * @return void The page is saved.
115
     **/
116
    public function updatePage($page_id, $page_title, $page_content, $page_slug)
117
    {
118
        $page = Page::find($page_id);
119
        $page->page_title = $page_title;
120
        $page->page_content = $page_content;
121
        $page->page_slug = $this->createSlug($page_slug);
122
        $page->touch();
123
124
        return $page->save();
125
    }
126
127
    /**
128
     * Deletes a page, possibly even with force.
129
     *
130
     * If $forceDelete is set to true, the page will be removed from the database (for ever).
131
     * If kept at false, the page will get a 'deleted_at' value and does not show until restored.
132
     *
133
     * @param int $page_id The id of the page.
134
     * @param bool $forceDelete Whether to really remove the page from the database or not.
135
     * @return void The page is deleted.
136
     **/
137
    public function deletePage($page_id, $forceDelete = false)
138
    {
139
        $page = Page::withTrashed()->find($page_id);
140
141
        if ($forceDelete) {
142
            return $page->forceDelete($page_id);
143
        } else {
144
            return $page->delete($page_id);
145
        }
146
    }
147
148
    /**
149
     * Restores a previously soft-deleted page.
150
     *
151
     * The id of the page can be retrieved with the getPageId() function.
152
     *
153
     * @param int $page_id The id of the page.
154
     * @return void The page is back!
155
     **/
156
    public function restorePage($page_id)
157
    {
158
        $page = Page::withTrashed()->find($page_id);
159
160
        return $page->restore($page_id);
161
    }
162
}
163