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/Parser.php (2 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 dokuwiki\Parsing;
4
5
use Doku_Handler;
6
use dokuwiki\Parsing\Lexer\Lexer;
7
use dokuwiki\Parsing\ParserMode\Base;
8
use dokuwiki\Parsing\ParserMode\ModeInterface;
9
10
/**
11
 * Sets up the Lexer with modes and points it to the Handler
12
 * For an intro to the Lexer see: wiki:parser
13
 */
14
class Parser {
15
16
    /** @var Doku_Handler */
17
    protected $handler;
18
19
    /** @var Lexer $lexer */
20
    protected $lexer;
21
22
    /** @var ModeInterface[] $modes */
23
    protected $modes = array();
24
25
    /** @var bool mode connections may only be set up once */
26
    protected $connected = false;
27
28
    /**
29
     * dokuwiki\Parsing\Doku_Parser constructor.
30
     *
31
     * @param Doku_Handler $handler
32
     */
33
    public function __construct(Doku_Handler $handler) {
34
        $this->handler = $handler;
35
    }
36
37
    /**
38
     * Adds the base mode and initialized the lexer
39
     *
40
     * @param Base $BaseMode
41
     */
42
    protected function addBaseMode($BaseMode) {
43
        $this->modes['base'] = $BaseMode;
44
        if(!$this->lexer) {
45
            $this->lexer = new Lexer($this->handler, 'base', true);
46
        }
47
        $this->modes['base']->Lexer = $this->lexer;
48
    }
49
50
    /**
51
     * Add a new syntax element (mode) to the parser
52
     *
53
     * PHP preserves order of associative elements
54
     * Mode sequence is important
55
     *
56
     * @param string $name
57
     * @param ModeInterface $Mode
58
     */
59
    public function addMode($name, ModeInterface $Mode) {
60
        if(!isset($this->modes['base'])) {
61
            $this->addBaseMode(new Base());
62
        }
63
        $Mode->Lexer = $this->lexer; // FIXME should be done by setter
0 ignored issues
show
Accessing Lexer on the interface dokuwiki\Parsing\ParserMode\ModeInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
64
        $this->modes[$name] = $Mode;
65
    }
66
67
    /**
68
     * Connect all modes with each other
69
     *
70
     * This is the last step before actually parsing.
71
     */
72
    protected function connectModes() {
73
74
        if($this->connected) {
75
            return;
76
        }
77
78
        foreach(array_keys($this->modes) as $mode) {
79
            // Base isn't connected to anything
80
            if($mode == 'base') {
81
                continue;
82
            }
83
            $this->modes[$mode]->preConnect();
84
85
            foreach(array_keys($this->modes) as $cm) {
86
87
                if($this->modes[$cm]->accepts($mode)) {
88
                    $this->modes[$mode]->connectTo($cm);
89
                }
90
91
            }
92
93
            $this->modes[$mode]->postConnect();
94
        }
95
96
        $this->connected = true;
97
    }
98
99
    /**
100
     * Parses wiki syntax to instructions
101
     *
102
     * @param string $doc the wiki syntax text
103
     * @return array instructions
104
     */
105
    public function parse($doc) {
106
        $this->connectModes();
107
        // Normalize CRs and pad doc
108
        $doc = "\n" . str_replace("\r\n", "\n", $doc) . "\n";
109
        $this->lexer->parse($doc);
110
111
        if (!method_exists($this->handler, 'finalize')) {
112
            /** @deprecated 2019-10 we have a legacy handler from a plugin, assume legacy _finalize exists */
113
114
            \dokuwiki\Debug\DebugHelper::dbgCustomDeprecationEvent(
115
                'finalize()',
116
                get_class($this->handler) . '::_finalize()',
117
                __METHOD__,
118
                __FILE__,
119
                __LINE__
120
            );
121
            $this->handler->_finalize();
0 ignored issues
show
The method _finalize() does not exist on Doku_Handler. Did you maybe mean finalize()?

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...
122
        } else {
123
            $this->handler->finalize();
124
        }
125
        return $this->handler->calls;
126
    }
127
128
}
129