Issues (3)

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/TwigResponder.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
namespace Germania\Responder;
3
4
use Twig\Environment as TwigEnvironment;
5
6
use Slim\Psr7\Factory\ResponseFactory;
7
use Psr\Http\Message\ResponseFactoryInterface;
8
use Psr\Http\Message\ResponseInterface;
9
10
class TwigResponder implements ResponderInterface
11
{
12
13 1
    use ResponseFactoryTrait;
14
15
    /**
16
     * @var TwigEnvironment
17
     */
18
    public $twig;
19
20
21
    /**
22
     * @var strinfg
23
     */
24
    public $template_field = "template";
25
26
27
    /**
28
     * @var array
29
     */
30
    public $default_context = array();
31
32
33
    /**
34
     * @var string|bool
35
     */
36
    public $default_template = false;
37
38
39
40
    /**
41
     * @param TwigEnvironment               $twig             Twig environment
42
     * @param string                        $template_field   Array field taht will contain template
43
     * @param array                         $default_context  Default template context
44
     * @param ResponseFactoryInterface|null $response_factory Optional: PSR-17 Response Factory
45
     */
46 2
    public function __construct( TwigEnvironment $twig, string $template_field, array $default_context = array(), ResponseFactoryInterface $response_factory = null )
47
    {
48 2
        $this->setTwig($twig);
49 2
        $this->setTemplateField($template_field);
50 2
        $this->setDefaultContext($default_context);
51 2
        $this->setResponseFactory($response_factory ?: new ResponseFactory);
52 2
    }
53
54
55
56
    /**
57
     * @param TwigEnvironment $twig
58
     */
59 6
    public function setTwig(TwigEnvironment $twig )
60
    {
61 6
        $this->twig = $twig;
62 6
        return $this;
63
    }
64
65
66
    /**
67
     * @return mixed
68
     */
69
    public function getDefaultTemplate( )
70
    {
71
        return $this->default_template;
72
    }
73
74
75
    /**
76
     * @param mixed $default_template
77
     */
78
    public function setDefaultTemplate( $default_template )
79
    {
80
        $this->default_template = $default_template;
81
        return $this;
82
    }
83
84
85
86
    /**
87
     * @param array $default_context
88
     */
89 6
    public function setDefaultContext( array $default_context )
90
    {
91 6
        $this->default_context = $default_context;
92 6
        return $this;
93
    }
94
95
96
    /**
97
     * @param string $field
98
     */
99 2
    public function setTemplateField( string $field )
100
    {
101 2
        $this->template_field = $field;
0 ignored issues
show
Documentation Bug introduced by
It seems like $field of type string is incompatible with the declared type object<Germania\Responder\strinfg> of property $template_field.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
102 2
        return $this;
103
    }
104
105
106
107
108
    /**
109
     * @inheritDoc
110
     */
111
    public function __invoke( $context ) : ResponseInterface
112
    {
113
        return $this->createResponse( $context );
114
    }
115
116
117
    /**
118
     * @inheritDoc
119
     * @param array|ArrayObject Context
120
     *
121
     * @throws  ResponderInvalidArgumentException
122
     * @throws  ResponderRuntimeException
123
     */
124 8
    public function createResponse( $context ) : ResponseInterface
125
    {
126 8
        if ($context instanceof \ArrayObject):
127 2
            $context = $context->getArrayCopy();
128 6
        elseif (!is_array($context)):
129 4
            $context_type = is_object($context) ? get_class($context) : gettype($context);
130 4
            $msg = sprintf(
131 4
                "Expected Array or ArrayObject, got '%s'.",
132
                $context_type
133
            );
134 4
            throw new ResponderInvalidArgumentException($msg);
135
        endif;
136
137
138
        // Merge with defaults
139 4
        $context = array_merge($this->default_context, $context);
140 4
        $template = $context[ $this->template_field ] ?? $this->getDefaultTemplate();
141
142 4
        if (!$template) {
143
            $msg = sprintf("Expected '%s' element.", $this->template_field);
144
            throw new ResponderRuntimeException($msg);
145
        }
146
147
        try {
148 4
            $website_html = $this->twig->render($template, $context);
149
150 4
            $response = $this->getResponseFactory()->createResponse();
151 4
            $response->getBody()->write($website_html);
152
        }
153
        catch (\Throwable $e) {
154
            throw new ResponderRuntimeException("Caught exception during response creation", 1, $e);
155
        }
156
157 4
        return $response;
158
    }
159
}
160