Issues (6)

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.

source/ExpressiveTemplateAdapter.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
 * @author stev leibelt <[email protected]>
4
 * @since 2016-02-03
5
 */
6
namespace Net\Bazzline\Component\Template;
7
8
use Zend\Expressive\Template\TemplatePath;
9
use Zend\Expressive\Template\TemplateRendererInterface;
10
11
class ExpressiveTemplateAdapter implements TemplateRendererInterface
12
{
13
    /** @var AbstractFileBasedTemplate */
14
    private $baseTemplate;
15
16
    /** @var array */
17
    private $defaultParameters = array();
18
19
    /** @var bool */
20
    private $defaultParametersProvided = false;
21
22
    /** @var array */
23
    private $fullQualifiedPathNameWithDefaultParameters = array();
24
25
    /** @var array|TemplatePath[] */
26
    private $fullQualifiedPathNameWithTemplatePath = array();
27
28
    /**
29
     * @param AbstractFileBasedTemplate $template
30
     */
31
    public function injectBaseTemplate(AbstractFileBasedTemplate $template)
32
    {
33
        $this->baseTemplate = $template;
34
    }
35
36
    /**
37
     * Render a template, optionally with parameters.
38
     *
39
     * Implementations MUST support the `namespace::template` naming convention,
40
     * and allow omitting the filename extension.
41
     *
42
     * @param string $name
43
     * @param array|object $params
44
     * @return string
45
     */
46
    public function render($name, $params = [])
47
    {
48
        if (isset($this->fullQualifiedPathNameWithTemplatePath[$name])) {
49
            $template   = $this->getNewTemplate();
50
            $path       = $this->fullQualifiedPathNameWithTemplatePath[$name];
51
52
            $template->setFilePath($path->getPath() . '.phtml');
53
54
            if ($this->defaultParametersProvided) {
55
                $template->assignMany($this->defaultParameters);
56
            }
57
58
            if (isset($this->fullQualifiedPathNameWithDefaultParameters[$name])) {
59
                $template->assignMany($this->fullQualifiedPathNameWithDefaultParameters[$name]);
60
            }
61
62
            if (!empty($params)) {
63
                $template->assignMany($params);
0 ignored issues
show
It seems like $params defined by parameter $params on line 46 can also be of type object; however, Net\Bazzline\Component\T...tTemplate::assignMany() does only seem to accept array, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
64
            }
65
66
            $content = $template->render();
67
        } else {
68
            $content = '';
69
        }
70
71
        return $content;
72
    }
73
74
    /**
75
     * Add a template path to the engine.
76
     *
77
     * Adds a template path, with optional namespace the templates in that path
78
     * provide.
79
     *
80
     * @param string $path
81
     * @param string $namespace
82
     */
83
    public function addPath($path, $namespace = null)
84
    {
85
        $key = (is_null($namespace)) ? $path : $namespace . '::' . $path;
86
87
        $this->fullQualifiedPathNameWithTemplatePath[$key] = new TemplatePath($path, $namespace);
88
    }
89
90
    /**
91
     * Retrieve configured paths from the engine.
92
     *
93
     * @return TemplatePath[]
94
     */
95
    public function getPaths()
96
    {
97
        return $this->fullQualifiedPathNameWithTemplatePath;
98
    }
99
100
    /**
101
     * Add a default parameter to use with a template.
102
     *
103
     * Use this method to provide a default parameter to use when a template is
104
     * rendered. The parameter may be overridden by providing it when calling
105
     * `render()`, or by calling this method again with a null value.
106
     *
107
     * The parameter will be specific to the template name provided. To make
108
     * the parameter available to any template, pass the TEMPLATE_ALL constant
109
     * for the template name.
110
     *
111
     * If the default parameter existed previously, subsequent invocations with
112
     * the same template name and parameter name will overwrite.
113
     *
114
     * @param string $templateName Name of template to which the param applies;
115
     *     use TEMPLATE_ALL to apply to all templates.
116
     * @param string $param Param name.
117
     * @param mixed $value
118
     */
119
    public function addDefaultParam($templateName, $param, $value)
120
    {
121
        $isDefaultForAllTemplates = ($templateName === self::TEMPLATE_ALL);
122
123
        if ($isDefaultForAllTemplates) {
124
            $this->defaultParameters[$param] = $value;
125
            $this->defaultParametersProvided = true;
126
        } else {
127
            $this->fullQualifiedPathNameWithDefaultParameters[$templateName] = array($param => $value);
128
        }
129
    }
130
131
    /**
132
     * @return AbstractFileBasedTemplate
133
     */
134
    private function getNewTemplate()
135
    {
136
        return clone $this->baseTemplate;
137
    }
138
}