Issues (14)

Security Analysis    not enabled

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.

Twig/NodeHelper.php (7 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 MewesK\TwigExcelBundle\Twig;
4
5
use MewesK\TwigExcelBundle\Twig\Node\SyntaxAwareNodeInterface;
6
use Twig_Error_Syntax;
7
use Twig_Node;
8
use Twig_Node_Block;
9
use Twig_Node_BlockReference;
10
use Twig_Node_Expression_MethodCall;
11
use Twig_Node_Expression_Name;
12
use Twig_Node_Text;
13
use Twig_Parser;
14
15
/**
16
 * Class NodeHelper
17
 *
18
 * @package MewesK\TwigExcelBundle\Twig\TokenParser
19
 */
20
class NodeHelper
21
{
22
    /**
23
     * Adds the PhpExcel instance as the last parameter to all macro function calls.
24
     *
25
     * @param Twig_Node $node
26
     */
27
    public static function fixMacroCallsRecursively(Twig_Node $node)
28
    {
29
        foreach ($node->getIterator() as $key => $subNode) {
30
            if ($subNode instanceof Twig_Node_Expression_MethodCall) {
0 ignored issues
show
The class Twig_Node_Expression_MethodCall does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
31
                /**
32
                 * @var \Twig_Node_Expression_Array $argumentsNode
33
                 */
34
                $argumentsNode = $subNode->getNode('arguments');
35
                $argumentsNode->addElement(new Twig_Node_Expression_Name('phpExcel', null), null);
36
            } elseif ($subNode instanceof Twig_Node && $subNode->count() > 0) {
0 ignored issues
show
The class Twig_Node does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
37
                self::fixMacroCallsRecursively($subNode);
38
            }
39
        }
40
    }
41
42
    /**
43
     * Removes all TextNodes that are in illegal places to avoid echos in unwanted places.
44
     *
45
     * @param Twig_Node $node
46
     * @param Twig_Parser $parser
47
     */
48
    public static function removeTextNodesRecursively(Twig_Node $node, Twig_Parser $parser)
49
    {
50
        foreach ($node->getIterator() as $key => $subNode) {
51
            if ($subNode instanceof Twig_Node_Text) {
0 ignored issues
show
The class Twig_Node_Text does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
52
                // Never delete a block body
53
                if ($key === 'body' && $node instanceof Twig_Node_Block) {
0 ignored issues
show
The class Twig_Node_Block does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
54
                    continue;
55
                }
56
57
                $node->removeNode($key);
58
            } elseif ($subNode instanceof Twig_Node_BlockReference) {
0 ignored issues
show
The class Twig_Node_BlockReference does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
59
                self::removeTextNodesRecursively($parser->getBlock($subNode->getAttribute('name')), $parser);
60
            } elseif ($subNode instanceof Twig_Node && $subNode->count() > 0) {
0 ignored issues
show
The class Twig_Node does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
61
                if ($subNode instanceof SyntaxAwareNodeInterface && $subNode->canContainText()) {
62
                    continue;
63
                }
64
                self::removeTextNodesRecursively($subNode, $parser);
65
            }
66
        }
67
    }
68
69
    /**
70
     * @param SyntaxAwareNodeInterface $node
71
     * @param array $path
72
     * @throws Twig_Error_Syntax
73
     */
74
    public static function checkAllowedParents(SyntaxAwareNodeInterface $node, array $path)
75
    {
76
        $parentName = null;
77
78
        foreach (array_reverse($path) as $className) {
79
            if (strpos($className, 'MewesK\TwigExcelBundle\Twig\Node\Xls') === 0) {
80
                $parentName = $className;
81
                break;
82
            }
83
        }
84
85
        if ($parentName === null) {
86
            return;
87
        }
88
89
        foreach ($node->getAllowedParents() as $className) {
90
            if ($className === $parentName) {
91
                return;
92
            }
93
        }
94
95
        throw new Twig_Error_Syntax(sprintf('Node "%s" is not allowed inside of Node "%s".', get_class($node), $parentName));
96
    }
97
98
    /**
99
     * @param Twig_Node $node
100
     * @return bool
101
     */
102
    public static function checkContainsXlsNode(Twig_Node $node)
103
    {
104
        foreach ($node->getIterator() as $key => $subNode) {
105
            if ($node instanceof SyntaxAwareNodeInterface) {
106
                return true;
107
            } elseif ($subNode instanceof Twig_Node && $subNode->count() > 0) {
0 ignored issues
show
The class Twig_Node does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
108
                if (self::checkContainsXlsNode($subNode)) {
109
                    return true;
110
                }
111
            }
112
        }
113
        return false;
114
    }
115
}
116