Issues (162)

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.

code/extensions/SlugableExtension.php (5 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
namespace Ntb\RestAPI;
4
5
/**
6
 * Extension for data objects which should be identifiable by a slug.
7
 *
8
 * The data objects need a Title attribute or getTitle method, which will be used to generate the slug. If no title is
9
 * provided, the extension uses a generic combination with class name and object id.
10
 * @author Christian Blank <[email protected]>
11
 */
12
class SlugableExtension extends \DataExtension {
13
    private static $db = [
14
        'URLSegment' => 'Varchar(200)'
15
    ];
16
17
    private static $indexes = [
18
        "URLSegment" => [
19
            'type' => 'unique',
20
            'value' => 'URLSegment'
21
        ]
22
    ];
23
24
    private static $defaults = [
25
        'Title' => 'New Element',
26
        'URLSegment' => 'new-element'
27
    ];
28
29
30
    /**
31
     * Set URLSegment to be unique on write
32
     */
33
    public function onBeforeWrite() {
34
        parent::onBeforeWrite();
35
36
        $defaults = $this->owner->config()->defaults;
37
        $URLSegment = $this->owner->URLSegment;
0 ignored issues
show
The property URLSegment does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
38
        // If there is no URLSegment set, generate one from Title
39
        if((!$URLSegment || $URLSegment == $defaults['URLSegment']) && $this->owner->Title != $defaults['Title']) {
40
            $URLSegment = $this->generateURLSegment($this->owner->Title);
0 ignored issues
show
The property Title does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
41
        } else if($this->owner->isChanged('URLSegment')) {
42
            // Make sure the URLSegment is valid for use in a URL
43
            $segment = preg_replace('/[^A-Za-z0-9]+/','-',$this->owner->URLSegment);
44
            $segment = preg_replace('/-+/','-',$segment);
45
            // If after sanitising there is no URLSegment, give it a reasonable default
46
            if(!$segment) {
47
                $segment = $this->fallbackUrl();
48
            }
49
            $URLSegment = $segment;
50
        }
51
        // Ensure that this object has a non-conflicting URLSegment value.
52
        $count = 2;
53
        $ID = $this->owner->ID;
0 ignored issues
show
The property ID does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
54
        while($this->lookForExistingURLSegment($URLSegment, $ID)) {
55
            $URLSegment = preg_replace('/-[0-9]+$/', null, $URLSegment) . '-' . $count;
56
            $count++;
57
        }
58
59
        $this->owner->URLSegment = $URLSegment;
60
    }
61
62
    /**
63
     * Check if there is already a database entry with this url segment
64
     *
65
     * @param string $urlSegment
66
     * @param int $id
67
     * @return bool
68
     */
69
    protected function lookForExistingURLSegment($urlSegment, $id) {
70
        return $this->owner->get()->filter(
71
            'URLSegment', $urlSegment
72
        )->exclude('ID', is_null($id) ? 0 : $id)->exists();
73
    }
74
75
    /**
76
     * Generate a URL segment based on the title provided.
77
     *
78
     * If {@link Extension}s wish to alter URL segment generation, they can do so by defining
79
     * updateURLSegment(&$url, $title).  $url will be passed by reference and should be modified.
80
     * $title will contain the title that was originally used as the source of this generated URL.
81
     * This lets extensions either start from scratch, or incrementally modify the generated URL.
82
     *
83
     * @param string $title the given title
84
     * @return string generated url segment
85
     */
86
    public function generateURLSegment($title) {
87
        $filter = \URLSegmentFilter::create();
88
        $t = $filter->filter($title);
89
        // Fallback to generic page name if path is empty (= no valid, convertable characters)
90
        if(!$t || $t == '-' || $t == '-1') {
91
            $t = $this->fallbackUrl();
92
        }
93
        // Hook for extensions
94
        $this->owner->extend('updateURLSegment', $t, $title);
95
        return $t;
96
    }
97
98
    private function fallbackUrl() {
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
99
        $className = strtolower(get_class($this->owner));
100
        return "$className-{$this->owner->ID}";
0 ignored issues
show
The property ID does not seem to exist in SS_Object.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
101
    }
102
103
}
104