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.

bin/wantedpages.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
#!/usr/bin/env php
2
<?php
3
4
use splitbrain\phpcli\CLI;
5
use splitbrain\phpcli\Options;
6
use dokuwiki\Utf8\Sort;
7
8
if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/');
9
define('NOSESSION', 1);
10
require_once(DOKU_INC . 'inc/init.php');
11
12
/**
13
 * Find wanted pages
14
 */
15
class WantedPagesCLI extends CLI {
16
17
    const DIR_CONTINUE = 1;
18
    const DIR_NS = 2;
19
    const DIR_PAGE = 3;
20
21
    private $skip = false;
22
    private $sort = 'wanted';
23
24
    private $result = array();
25
26
    /**
27
     * Register options and arguments on the given $options object
28
     *
29
     * @param Options $options
30
     * @return void
31
     */
32
    protected function setup(Options $options) {
33
        $options->setHelp(
34
            'Outputs a list of wanted pages (pages that do not exist yet) and their origin pages ' .
35
            ' (the pages that are linkin to these missing pages).'
36
        );
37
        $options->registerArgument(
38
            'namespace',
39
            'The namespace to lookup. Defaults to root namespace',
40
            false
41
        );
42
43
        $options->registerOption(
44
            'sort',
45
            'Sort by wanted or origin page',
46
            's',
47
            '(wanted|origin)'
48
        );
49
50
        $options->registerOption(
51
            'skip',
52
            'Do not show the second dimension',
53
            'k'
54
        );
55
    }
56
57
    /**
58
     * Your main program
59
     *
60
     * Arguments and options have been parsed when this is run
61
     *
62
     * @param Options $options
63
     * @return void
64
     */
65
    protected function main(Options $options) {
66
        $args = $options->getArgs();
67
        if($args) {
68
            $startdir = dirname(wikiFN($args[0] . ':xxx'));
69
        } else {
70
            $startdir = dirname(wikiFN('xxx'));
71
        }
72
73
        $this->skip = $options->getOpt('skip');
0 ignored issues
show
Documentation Bug introduced by
It seems like $options->getOpt('skip') can also be of type string or array<integer,string>. However, the property $skip is declared as type boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
74
        $this->sort = $options->getOpt('sort');
0 ignored issues
show
Documentation Bug introduced by
It seems like $options->getOpt('sort') can also be of type boolean or array<integer,string>. However, the property $sort is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
75
76
        $this->info("searching $startdir");
77
78
        foreach($this->getPages($startdir) as $page) {
79
            $this->internalLinks($page);
80
        }
81
        Sort::ksort($this->result);
82
        foreach($this->result as $main => $subs) {
83
            if($this->skip) {
84
                print "$main\n";
85
            } else {
86
                $subs = array_unique($subs);
87
                Sort::sort($subs);
88
                foreach($subs as $sub) {
89
                    printf("%-40s %s\n", $main, $sub);
90
                }
91
            }
92
        }
93
    }
94
95
    /**
96
     * Determine directions of the search loop
97
     *
98
     * @param string $entry
99
     * @param string $basepath
100
     * @return int
101
     */
102
    protected function dirFilter($entry, $basepath) {
103
        if($entry == '.' || $entry == '..') {
104
            return WantedPagesCLI::DIR_CONTINUE;
105
        }
106
        if(is_dir($basepath . '/' . $entry)) {
107
            if(strpos($entry, '_') === 0) {
108
                return WantedPagesCLI::DIR_CONTINUE;
109
            }
110
            return WantedPagesCLI::DIR_NS;
111
        }
112
        if(preg_match('/\.txt$/', $entry)) {
113
            return WantedPagesCLI::DIR_PAGE;
114
        }
115
        return WantedPagesCLI::DIR_CONTINUE;
116
    }
117
118
    /**
119
     * Collects recursively the pages in a namespace
120
     *
121
     * @param string $dir
122
     * @return array
123
     * @throws DokuCLI_Exception
124
     */
125
    protected function getPages($dir) {
126
        static $trunclen = null;
127
        if(!$trunclen) {
128
            global $conf;
129
            $trunclen = strlen($conf['datadir'] . ':');
130
        }
131
132
        if(!is_dir($dir)) {
133
            throw new DokuCLI_Exception("Unable to read directory $dir");
134
        }
135
136
        $pages = array();
137
        $dh = opendir($dir);
138
        while(false !== ($entry = readdir($dh))) {
139
            $status = $this->dirFilter($entry, $dir);
140
            if($status == WantedPagesCLI::DIR_CONTINUE) {
141
                continue;
142
            } else if($status == WantedPagesCLI::DIR_NS) {
143
                $pages = array_merge($pages, $this->getPages($dir . '/' . $entry));
144
            } else {
145
                $page = array(
146
                    'id' => pathID(substr($dir . '/' . $entry, $trunclen)),
147
                    'file' => $dir . '/' . $entry,
148
                );
149
                $pages[] = $page;
150
            }
151
        }
152
        closedir($dh);
153
        return $pages;
154
    }
155
156
    /**
157
     * Parse instructions and add the non-existing links to the result array
158
     *
159
     * @param array $page array with page id and file path
160
     */
161
    protected function internalLinks($page) {
162
        global $conf;
163
        $instructions = p_get_instructions(file_get_contents($page['file']));
164
        $cns = getNS($page['id']);
165
        $exists = false;
166
        $pid = $page['id'];
167
        foreach($instructions as $ins) {
168
            if($ins[0] == 'internallink' || ($conf['camelcase'] && $ins[0] == 'camelcaselink')) {
169
                $mid = $ins[1][0];
170
                resolve_pageid($cns, $mid, $exists);
171
                if(!$exists) {
172
                    list($mid) = explode('#', $mid); //record pages without hashes
173
174
                    if($this->sort == 'origin') {
175
                        $this->result[$pid][] = $mid;
176
                    } else {
177
                        $this->result[$mid][] = $pid;
178
                    }
179
                }
180
            }
181
        }
182
    }
183
}
184
185
// Main
186
$cli = new WantedPagesCLI();
187
$cli->run();
188