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/StyleChooser/StyleChooserController.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
namespace Anax\StyleChooser;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
/**
9
 * Style chooser controller loads available stylesheets from a directory and
10
 * lets the user choose the stylesheet to use.
11
 */
12
class StyleChooserController implements ContainerInjectableInterface
13
{
14
    use ContainerInjectableTrait;
15
16
17
18
    /**
19
     * @var string $cssUrl The baseurl to where the css files are.
20
     * @var string $cssDir The path to the directory storing css files.
21
     * @var array  $styles The styles available in the style directory.
22
     * @var string $key    The session key used to store the active style.
23
     */
24
    private $cssUrl = "css";
25
    private $cssDir = ANAX_INSTALL_PATH . "/htdocs/css";
26
    private $styles = [];
27
    private static $key = "AnaxStyleChooser";
28
29
30
31
    /**
32
     * Get the session key to use to retrieve the active stylesheet.
33
     *
34
     * @return string
35
     */
36
    public static function getSessionKey() : string
37
    {
38
        return self::$key;
39
    }
40
41
42
43
    /**
44
     * The initialize method is optional and will always be called before the
45
     * target method/action. This is a convienient method where you could
46
     * setup internal properties that are commonly used by several methods.
47
     *
48
     * @return void
49
     */
50
    public function initialize() : void
51
    {
52
        foreach (glob("{$this->cssDir}/*.css") as $file) {
53
            $filename = basename($file);
54
            $url = "{$this->cssUrl}/$filename";
55
            $content = file_get_contents($file);
56
            $comment = strstr($content, "*/", true);
57
            $comment = preg_replace(["#\/\*!#", "#\*#"], "", $comment);
58
            $comment = preg_replace("#@#", "<br>@", $comment);
59
            $first = strpos($comment, ".");
60
            $short = substr($comment, 0, $first + 1);
61
            $long = substr($comment, $first + 1);
62
            $this->styles[$url] = [
63
                "shortDescription" => $short,
64
                "longDescription" => $long,
65
            ];
66
        }
67
68
        foreach ($this->styles as $key => $value) {
69
            $isMinified = strstr($key, ".min.css", true);
70
            if ($isMinified) {
71
                unset($this->styles["$isMinified.css"]);
72
            }
73
        }
74
    }
75
76
77
78
    /**
79
     * Display the stylechooser with details on current selected style.
80
     *
81
     * @return object
82
     */
83
    public function indexAction() : object
84
    {
85
        $title = "Stylechooser";
86
87
        $page = $this->di->get("page");
88
        $session = $this->di->get("session");
89
90
        $active = $session->get(self::$key, null);
91
92
        $page->add("anax/v2/stylechooser/default", [
93
            "styles" => $this->styles,
94
            "activeStyle" => $active,
95
            "activeShortDescription" => $this->styles[$active]["shortDescription"] ?? null,
96
            "activeLongDescription" => $this->styles[$active]["longDescription"] ?? null,
97
        ]);
98
99
        return $page->render([
100
            "title" => $title,
101
        ]);
102
    }
103
104
105
106
    /**
107
     * Update current selected style.
108
     *
109
     * @return object
110
     */
111
    public function updateActionPost() : object
112
    {
113
        $response = $this->di->get("response");
114
        $request = $this->di->get("request");
115
        $session = $this->di->get("session");
116
        $key = $request->getPost("stylechooser");
117
118
        if ($key === "none") {
119
            $session->set("flashmessage", "Unsetting the style and using deafult style.");
120
            $session->set(self::$key, null);
121 View Code Duplication
        } elseif (array_key_exists($key, $this->styles)) {
0 ignored issues
show
This code seems to be duplicated across 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...
122
            $session->set("flashmessage", "Using the style '$key'.");
123
            $session->set(self::$key, $key);
124
        }
125
126
        return $response->redirect("style");
127
    }
128
129
130
131
    /**
132
     * Update current selected style using a GET url and redirect to last
133
     * page visited.
134
     *
135
     * @param string $style the key to the style to use.
136
     *
137
     * @return object
138
     */
139
    public function updateActionGet($style) : object
140
    {
141
        $response = $this->di->get("response");
142
        $session = $this->di->get("session");
143
144
        $key = $this->cssUrl . "/" . $style . ".css";
145
        $keyMin = $this->cssUrl . "/" . $style . ".min.css";
146
147
        if ($style === "none") {
148
            $session->set("flashmessage", "Unsetting the style and using the default style.");
149
            $session->set(self::$key, null);
150 View Code Duplication
        } elseif (array_key_exists($keyMin, $this->styles)) {
0 ignored issues
show
This code seems to be duplicated across 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...
151
            $session->set("flashmessage", "Now using the style '$keyMin'.");
152
            $session->set(self::$key, $keyMin);
153
        } elseif (array_key_exists($key, $this->styles)) {
154
            $session->set("flashmessage", "Now using the style '$key'.");
155
            $session->set(self::$key, $key);
156
        }
157
158
        $url = $session->getOnce("redirect", "style");
159
        return $response->redirect($url);
160
    }
161
}
162