Issues (847)

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.

inc/Parsing/Handler/Block.php (2 issues)

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
namespace dokuwiki\Parsing\Handler;
4
5
/**
6
 * Handler for paragraphs
7
 *
8
 * @author Harry Fuecks <[email protected]>
9
 */
10
class Block
11
{
12
    protected $calls = array();
13
    protected $skipEol = false;
14
    protected $inParagraph = false;
15
16
    // Blocks these should not be inside paragraphs
17
    protected $blockOpen = array(
18
        'header',
19
        'listu_open','listo_open','listitem_open','listcontent_open',
20
        'table_open','tablerow_open','tablecell_open','tableheader_open','tablethead_open',
21
        'quote_open',
22
        'code','file','hr','preformatted','rss',
23
        'htmlblock','phpblock',
24
        'footnote_open',
25
    );
26
27
    protected $blockClose = array(
28
        'header',
29
        'listu_close','listo_close','listitem_close','listcontent_close',
30
        'table_close','tablerow_close','tablecell_close','tableheader_close','tablethead_close',
31
        'quote_close',
32
        'code','file','hr','preformatted','rss',
33
        'htmlblock','phpblock',
34
        'footnote_close',
35
    );
36
37
    // Stacks can contain paragraphs
38
    protected $stackOpen = array(
39
        'section_open',
40
    );
41
42
    protected $stackClose = array(
43
        'section_close',
44
    );
45
46
47
    /**
48
     * Constructor. Adds loaded syntax plugins to the block and stack
49
     * arrays
50
     *
51
     * @author Andreas Gohr <[email protected]>
52
     */
53
    public function __construct()
54
    {
55
        global $DOKU_PLUGINS;
56
        //check if syntax plugins were loaded
57
        if (empty($DOKU_PLUGINS['syntax'])) return;
58
        foreach ($DOKU_PLUGINS['syntax'] as $n => $p) {
59
            $ptype = $p->getPType();
60
            if ($ptype == 'block') {
61
                $this->blockOpen[]  = 'plugin_'.$n;
62
                $this->blockClose[] = 'plugin_'.$n;
63
            } elseif ($ptype == 'stack') {
64
                $this->stackOpen[]  = 'plugin_'.$n;
65
                $this->stackClose[] = 'plugin_'.$n;
66
            }
67
        }
68
    }
69
70
    protected function openParagraph($pos)
71
    {
72
        if ($this->inParagraph) return;
73
        $this->calls[] = array('p_open',array(), $pos);
74
        $this->inParagraph = true;
75
        $this->skipEol = true;
76
    }
77
78
    /**
79
     * Close a paragraph if needed
80
     *
81
     * This function makes sure there are no empty paragraphs on the stack
82
     *
83
     * @author Andreas Gohr <[email protected]>
84
     *
85
     * @param string|integer $pos
86
     */
87
    protected function closeParagraph($pos)
88
    {
89
        if (!$this->inParagraph) return;
90
        // look back if there was any content - we don't want empty paragraphs
91
        $content = '';
92
        $ccount = count($this->calls);
93
        for ($i=$ccount-1; $i>=0; $i--) {
94
            if ($this->calls[$i][0] == 'p_open') {
95
                break;
96
            } elseif ($this->calls[$i][0] == 'cdata') {
97
                $content .= $this->calls[$i][1][0];
98
            } else {
99
                $content = 'found markup';
100
                break;
101
            }
102
        }
103
104
        if (trim($content)=='') {
105
            //remove the whole paragraph
106
            //array_splice($this->calls,$i); // <- this is much slower than the loop below
107
            for ($x=$ccount; $x>$i;
108
            $x--) array_pop($this->calls);
109
        } else {
110
            // remove ending linebreaks in the paragraph
111
            $i=count($this->calls)-1;
112
            if ($this->calls[$i][0] == 'cdata') $this->calls[$i][1][0] = rtrim($this->calls[$i][1][0], "\n");
113
            $this->calls[] = array('p_close',array(), $pos);
114
        }
115
116
        $this->inParagraph = false;
117
        $this->skipEol = true;
118
    }
119
120
    protected function addCall($call)
121
    {
122
        $key = count($this->calls);
123
        if ($key and ($call[0] == 'cdata') and ($this->calls[$key-1][0] == 'cdata')) {
124
            $this->calls[$key-1][1][0] .= $call[1][0];
125
        } else {
126
            $this->calls[] = $call;
127
        }
128
    }
129
130
    // simple version of addCall, without checking cdata
131
    protected function storeCall($call)
132
    {
133
        $this->calls[] = $call;
134
    }
135
136
    /**
137
     * Processes the whole instruction stack to open and close paragraphs
138
     *
139
     * @author Harry Fuecks <[email protected]>
140
     * @author Andreas Gohr <[email protected]>
141
     *
142
     * @param array $calls
143
     *
144
     * @return array
145
     */
146
    public function process($calls)
147
    {
148
        // open first paragraph
149
        $this->openParagraph(0);
150
        foreach ($calls as $key => $call) {
151
            $cname = $call[0];
152
            if ($cname == 'plugin') {
153
                $cname='plugin_'.$call[1][0];
154
                $plugin = true;
155
                $plugin_open = (($call[1][2] == DOKU_LEXER_ENTER) || ($call[1][2] == DOKU_LEXER_SPECIAL));
156
                $plugin_close = (($call[1][2] == DOKU_LEXER_EXIT) || ($call[1][2] == DOKU_LEXER_SPECIAL));
157
            } else {
158
                $plugin = false;
159
            }
160
            /* stack */
161
            if (in_array($cname, $this->stackClose) && (!$plugin || $plugin_close)) {
0 ignored issues
show
The variable $plugin_close does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
162
                $this->closeParagraph($call[2]);
163
                $this->storeCall($call);
164
                $this->openParagraph($call[2]);
165
                continue;
166
            }
167
            if (in_array($cname, $this->stackOpen) && (!$plugin || $plugin_open)) {
0 ignored issues
show
The variable $plugin_open does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
168
                $this->closeParagraph($call[2]);
169
                $this->storeCall($call);
170
                $this->openParagraph($call[2]);
171
                continue;
172
            }
173
            /* block */
174
            // If it's a substition it opens and closes at the same call.
175
            // To make sure next paragraph is correctly started, let close go first.
176
            if (in_array($cname, $this->blockClose) && (!$plugin || $plugin_close)) {
177
                $this->closeParagraph($call[2]);
178
                $this->storeCall($call);
179
                $this->openParagraph($call[2]);
180
                continue;
181
            }
182
            if (in_array($cname, $this->blockOpen) && (!$plugin || $plugin_open)) {
183
                $this->closeParagraph($call[2]);
184
                $this->storeCall($call);
185
                continue;
186
            }
187
            /* eol */
188
            if ($cname == 'eol') {
189
                // Check this isn't an eol instruction to skip...
190
                if (!$this->skipEol) {
191
                    // Next is EOL => double eol => mark as paragraph
192
                    if (isset($calls[$key+1]) && $calls[$key+1][0] == 'eol') {
193
                        $this->closeParagraph($call[2]);
194
                        $this->openParagraph($call[2]);
195
                    } else {
196
                        //if this is just a single eol make a space from it
197
                        $this->addCall(array('cdata',array("\n"), $call[2]));
198
                    }
199
                }
200
                continue;
201
            }
202
            /* normal */
203
            $this->addCall($call);
204
            $this->skipEol = false;
205
        }
206
        // close last paragraph
207
        $call = end($this->calls);
208
        $this->closeParagraph($call[2]);
209
        return $this->calls;
210
    }
211
}
212