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/TwitalLoaderTrait.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
namespace Goetas\Twital;
4
5
use Goetas\Twital\SourceAdapter\HTML5Adapter;
6
use Goetas\Twital\SourceAdapter\XHTMLAdapter;
7
use Goetas\Twital\SourceAdapter\XMLAdapter;
8
use Twig\Environment;
9
use Twig\Error\LoaderError;
10
use Twig\Loader\ExistsLoaderInterface;
11
use Twig\Loader\LoaderInterface;
12
use Twig\Loader\SourceContextLoaderInterface;
13
use Twig\Source;
14
15
/**
16
 * @author Martin Hasoň <[email protected]>
17
 */
18
trait TwitalLoaderTrait
19
{
20
    /**
21
     * Array of patterns used to decide if a template is twital-compilable or not.
22
     * Items are strings or callbacks
23
     *
24
     * @var array
25
     */
26
    protected $sourceAdapters = array();
27
28
    /**
29
     * The internal Twital compiler
30
     *
31
     * @var Twital
32
     */
33
    protected $twital;
34
35
    /**
36
     * The wrapped Twig loader
37
     *
38
     * @var LoaderInterface|\Twig_LoaderInterface
39
     */
40
    protected $loader;
41
42
    /**
43
     * Creates a new Twital loader.
44
     *
45
     * @param LoaderInterface $loader
46
     * @param Twital $twital
47
     * @param bool $addDefaults If NULL, some standard rules will be used (`*.twital.*` and `*.twital`).
48
     */
49
    public function __construct(LoaderInterface $loader = null, Twital $twital = null, $addDefaults = true)
50
    {
51
        $this->loader = $loader;
52
        $this->twital = $twital;
53
54
        if ($addDefaults === true || (is_array($addDefaults) && in_array('html', $addDefaults))) {
55
            $this->addSourceAdapter('/\.twital\.html$/i', new HTML5Adapter());
56
        }
57
        if ($addDefaults === true || (is_array($addDefaults) && in_array('xml', $addDefaults))) {
58
            $this->addSourceAdapter('/\.twital\.xml$/i', new XMLAdapter());
59
        }
60
        if ($addDefaults === true || (is_array($addDefaults) && in_array('xhtml', $addDefaults))) {
61
            $this->addSourceAdapter('/\.twital\.xhtml$/i', new XHTMLAdapter());
62
        }
63
    }
64
65
    /**
66
     * Add a new pattern that can decide if a template is twital-compilable or not.
67
     * If $pattern is a string, then must be a valid regex that matches the template filename.
68
     * If $pattern is a callback, then must return true if the template is compilable, false otherwise.
69
     *
70
     * @param string|callback $pattern
71
     * @param SourceAdapter $adapter
72
     * @return TwitalLoader
73
     */
74
    public function addSourceAdapter($pattern, SourceAdapter $adapter)
75
    {
76
        $this->sourceAdapters[$pattern] = $adapter;
77
78
        return $this;
79
    }
80
81
    /**
82
     * Get all patterns used to choose if a template is twital-compilable or not
83
     *
84
     * @return array:
85
     */
86
    public function getSourceAdapters()
87
    {
88
        return $this->sourceAdapters;
89
    }
90
91
    /**
92
     * Decide if a template is twital-compilable or not.
93
     *
94
     * @param string $name
95
     * @return SourceAdapter
96
     */
97
    public function getSourceAdapter($name)
98
    {
99
        foreach (array_reverse($this->sourceAdapters) as $pattern => $adapter) {
100
            if (preg_match($pattern, $name)) {
101
                return $adapter;
102
            }
103
        }
104
105
        return null;
106
    }
107
108
    /**
109
     * Get the wrapped Twig loader
110
     *
111
     * @return LoaderInterface|\Twig_LoaderInterface
112
     */
113
    public function getLoader()
114
    {
115
        return $this->loader;
116
    }
117
118
    /**
119
     * Set the wrapped Twig loader
120
     *
121
     * @param LoaderInterface|\Twig_LoaderInterface $loader
122
     * @return TwitalLoader
123
     */
124
    public function setLoader($loader)
125
    {
126
        $this->loader = $loader;
127
128
        return $this;
129
    }
130
131
    /**
132
     * @return Twital
133
     */
134
    public function getTwital()
135
    {
136
        if ($this->twital === null) {
137
            $this->twital = new Twital();
138
        }
139
140
        return $this->twital;
141
    }
142
143
    private function doGetSourceContext($name)
144
    {
145
        if (Environment::MAJOR_VERSION >= 2 || $this->loader instanceof SourceContextLoaderInterface) {
146
            $originalContext = $this->loader->getSourceContext($name);
147
            $code = $originalContext->getCode();
148
            $path = $originalContext->getPath();
149
        } else {
150
            $code = $this->loader->getSource($name);
151
            $path = null;
152
        }
153
154
        if ($adapter = $this->getSourceAdapter($name)) {
155
            $code = $this->getTwital()->compile($adapter, $code);
156
        }
157
158
        return new Source($code, $name, $path);
159
    }
160
161
    private function doExists($name)
162
    {
163
        if (Environment::MAJOR_VERSION >= 2 || $this->loader instanceof ExistsLoaderInterface) {
164
            return $this->loader->exists($name);
165
        } else {
166
            try {
167
                $this->getSourceContext($name);
0 ignored issues
show
The method getSourceContext() does not exist on Goetas\Twital\TwitalLoaderTrait. Did you maybe mean doGetSourceContext()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
168
169
                return true;
170
            } catch (LoaderError $e) {
171
                return false;
172
            }
173
        }
174
    }
175
}
176