Issues (22)

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.

Tests/Twig/Node/GimmeNodeTest.php (3 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
/*
4
 * This file is part of the Superdesk Web Publisher Templates System.
5
 *
6
 * Copyright 2015 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Component\TemplatesSystem\Tests\Twig\Node;
16
17
use Doctrine\Common\Cache\ArrayCache;
18
use SWP\Component\TemplatesSystem\Gimme\Context\Context;
19
use SWP\Component\TemplatesSystem\Gimme\Factory\MetaFactory;
20
use SWP\Component\TemplatesSystem\Gimme\Loader\ArticleLoader;
21
use SWP\Component\TemplatesSystem\Gimme\Loader\ChainLoader;
22
use SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension;
23
use SWP\Component\TemplatesSystem\Twig\Node\GimmeNode;
24
use Symfony\Component\EventDispatcher\EventDispatcher;
25
use Twig\Node\Expression\ArrayExpression;
26
use Twig\Test\NodeTestCase;
27
use Twig\Loader\ArrayLoader;
28
use Twig\Environment;
29
use Twig\Node\Node;
30
use Twig\Node\TextNode;
31
use Twig\Node\Expression\ConstantExpression;
32
use Twig\Node\Expression\AssignNameExpression;
33
34
class GimmeNodeTest extends NodeTestCase
35
{
36 View Code Duplication
    public function testConstructor()
0 ignored issues
show
This method seems to be duplicated in 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...
37
    {
38
        $annotation = new Node([new AssignNameExpression('article', 1)]);
39
        $parameters = new ArrayExpression([], 1);
40
        $body = new TextNode('', 1);
41
        $node = new GimmeNode($annotation, $parameters, null, $body, 1, 'gimme');
42
        $this->assertEquals($annotation, $node->getNode('annotation'));
43
        $this->assertEquals($parameters, $node->getNode('parameters'));
44
        $this->assertEquals($body, $node->getNode('body'));
45
    }
46
47
    public function getTests()
48
    {
49
        $annotation1 = new Node([new AssignNameExpression('article', 1)]);
50
        $parameters1 = new ArrayExpression([], 1);
51
        $body1 = new TextNode('Test body', 1);
52
        $node1 = new GimmeNode($annotation1, $parameters1, null, $body1, 1, 'gimme');
53
54
        $annotation2 = new Node([new AssignNameExpression('article', 2)]);
55
        $body2 = new TextNode('Test body', 2);
56
        $node2 = new GimmeNode($annotation2, null, null, $body2, 2, 'gimme');
57
58
        $annotation3 = new Node([new AssignNameExpression('article', 3)]);
59
        $parameters3 = new ArrayExpression([new ConstantExpression('foo', 1), new ConstantExpression(true, 1)], 1);
60
        $body3 = new TextNode('Test body', 3);
61
        $node3 = new GimmeNode($annotation3, $parameters3, null, $body3, 3, 'gimme');
62
63
        $annotation4 = new Node([new AssignNameExpression('article', 3)]);
64
        $parameters4 = new ArrayExpression([new ConstantExpression('foo', 1), new ConstantExpression(true, 1)], 1);
65
        $ignoreContext4 = new ArrayExpression([], 1);
66
        $body4 = new TextNode('Test body', 4);
67
        $node4 = new GimmeNode($annotation4, $parameters4, $ignoreContext4, $body4, 4, 'gimme');
68
69
        return [
70
            [$node1, <<<'EOF'
71
// line 1
72
$swpMetaLoader3 = $this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader();
73
$context["article"] = $swpMetaLoader3->load("article", []);
74
if ($context["article"] !== false) {
75
    echo "Test body";
76
}
77
unset($context["article"]);
78
EOF
79
            ],
80
            [$node2, <<<'EOF'
81
// line 2
82
$swpMetaLoader4 = $this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader();
83
$context["article"] = $swpMetaLoader4->load("article", null);
84
if ($context["article"] !== false) {
85
    echo "Test body";
86
}
87
unset($context["article"]);
88
EOF
89
            ],
90
            [$node3, <<<'EOF'
91
// line 3
92
$swpMetaLoader5 = $this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader();
93
$context["article"] = $swpMetaLoader5->load("article", ["foo" => true]);
94
if ($context["article"] !== false) {
95
    echo "Test body";
96
}
97
unset($context["article"]);
98
EOF
99
            ],
100
            [$node4, <<<'EOF'
101
// line 4
102
$swpMetaLoader6 = $this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getLoader();
103
$swpContext6Gimme = $this->env->getExtension('SWP\Component\TemplatesSystem\Twig\Extension\GimmeExtension')->getContext();
104
$swpIgnoreContext6Gimme = $swpContext6Gimme->temporaryUnset([]);
105
$context["article"] = $swpMetaLoader6->load("article", ["foo" => true]);
106
if ($context["article"] !== false) {
107
    echo "Test body";
108
}
109
$swpContext6Gimme->restoreTemporaryUnset($swpIgnoreContext6Gimme);
110
unset($context["article"]);
111
EOF
112
            ],
113
        ];
114
    }
115
116
    public function testTemplateString()
117
    {
118
        $loader = new ArrayLoader([
119
            'clear_gimme' => '{% gimme article %}{{ article.title }}{% endgimme %}',
120
            'gimme_with_parameters' => '{% gimme article with {id: 1} %}{{ article.title }}{% endgimme %}',
121
        ]);
122
        $metaLoader = new ChainLoader();
123
        $context = new Context(new EventDispatcher(), new ArrayCache());
124
        $metaLoader->addLoader(new ArticleLoader(__DIR__, new MetaFactory($context)));
125
        $twig = new Environment($loader);
126
        $twig->addExtension(new GimmeExtension($context, $metaLoader));
127
128
        $this->assertEquals($twig->render('clear_gimme'), 'New article');
129
        $this->assertEquals($twig->render('gimme_with_parameters'), 'New article');
130
    }
131
132
    public function testBrokenTemplate()
133
    {
134
        $loader = new ArrayLoader([
135
            'error_gimme' => '{% gimme article {id: 1} %}{{ article.title }}{% endgimme %}',
136
        ]);
137
        $metaLoader = new ChainLoader();
138
        $context = new Context(new EventDispatcher(), new ArrayCache());
139
        $metaLoader->addLoader(new ArticleLoader(__DIR__, new MetaFactory($context)));
140
        $twig = new Environment($loader);
141
        $twig->addExtension(new GimmeExtension($context, $metaLoader));
142
143
        $this->expectException(\Twig\Error\SyntaxError::class);
144
        $twig->render('error_gimme');
145
    }
146
147 View Code Duplication
    protected function tearDown()
0 ignored issues
show
This method seems to be duplicated in 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...
148
    {
149
        $reflection = new \ReflectionObject($this);
150
        foreach ($reflection->getProperties() as $prop) {
151
            if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
0 ignored issues
show
Consider using $prop->class. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
152
                $prop->setAccessible(true);
153
                $prop->setValue($this, null);
154
            }
155
        }
156
    }
157
}
158