Issues (141)

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.

src/Graph/GraphPrinter.php (1 issue)

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 SRF\Graph;
4
5
use SMW\ResultPrinter;
6
use SMWQueryResult;
7
use SMWWikiPageValue;
8
use GraphViz;
9
use Html;
10
11
/**
12
 * SMW result printer for graphs using graphViz.
13
 * In order to use this printer you need to have both
14
 * the graphViz library installed on your system and
15
 * have the graphViz MediaWiki extension installed.
16
 *
17
 * @file SRF_Graph.php
18
 * @ingroup SemanticResultFormats
19
 *
20
 * @licence GNU GPL v2+
21
 * @author Frank Dengler
22
 * @author Jeroen De Dauw < [email protected] >
23
 * @author Sebastian Schmid
24
 */
25
class GraphPrinter extends ResultPrinter {
26
27
	//@see https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/4273
28
	// Implement `ResultPrinterDependency` once SMW 3.1 becomes mandatory
29
30
	const NODELABEL_DISPLAYTITLE = 'displaytitle';
31
	public static $NODE_LABELS = [
32
		self::NODELABEL_DISPLAYTITLE,
33
	];
34
35
	public static $NODE_SHAPES = [
36
		'box',
37
		'box3d',
38
		'circle',
39
		'component',
40
		'diamond',
41
		'doublecircle',
42
		'doubleoctagon',
43
		'egg',
44
		'ellipse',
45
		'folder',
46
		'hexagon',
47
		'house',
48
		'invhouse',
49
		'invtrapezium',
50
		'invtriangle',
51
		'Mcircle',
52
		'Mdiamond',
53
		'Msquare',
54
		'Mrecord',
55
		'none',
56
		'note',
57
		'octagon',
58
		'parallelogram',
59
		'pentagon ',
60
		'plaintext',
61
		'point',
62
		'polygon',
63
		'rect',
64
		'record',
65
		'rectangle',
66
		'septagon',
67
		'square',
68
		'tab',
69
		'trapezium',
70
		'triangle',
71
		'tripleoctagon',
72
	];
73
74
	public static $ARROW_SHAPES = [
75
		'box',
76
		'crow',
77
		'curve',
78
		'icurve',
79
		'diamond',
80
		'dot',
81
		'inv',
82
		'none',
83
		'normal',
84
		'tee',
85
		'vee',
86
	];
87
88
	private $nodes = [];
89
	private $options;
90
91
	public function getName() {
92
		return $this->msg( 'srf-printername-graph' )->text();
93
	}
94
95
	/**
96
	 * @see SMWResultPrinter::handleParameters()
97
	 */
98
	protected function handleParameters( array $params, $outputmode ) {
99
		parent::handleParameters( $params, $outputmode );
100
101
		$this->options = new GraphOptions($params);
102
	}
103
104
	/**
105
	 * @see ResultPrinterDependency::hasMissingDependency
106
	 *
107
	 * {@inheritDoc}
108
	 */
109
	public function hasMissingDependency() {
110
		return !class_exists( 'GraphViz' ) && !class_exists( '\\MediaWiki\\Extension\\GraphViz\\GraphViz' );
111
	}
112
113
	/**
114
	 * @see ResultPrinterDependency::getDependencyError
115
	 *
116
	 * {@inheritDoc}
117
	 */
118
	public function getDependencyError() {
119
		return Html::rawElement(
120
			'div',
121
			[
122
				'class' => 'smw-callout smw-callout-error'
123
			],
124
			'The SRF Graph printer requires the GraphViz extension to be installed.'
125
		);
126
	}
127
128
	/**
129
	 * @param SMWQueryResult $res
130
	 * @param $outputmode
131
	 *
132
	 * @return string
133
	 */
134
	protected function getResultText( SMWQueryResult $res, $outputmode ) {
135
136
		// Remove this once SRF requires 3.1+
137
		if ( $this->hasMissingDependency() ) {
138
			return $this->getDependencyError();
139
		}
140
141
		// iterate query result and create SRF\GraphNodes
142
		while ( $row = $res->getNext() ) {
143
			$this->processResultRow( $row );
144
		}
145
146
		// use GraphFormater to build the graph
147
		$graphFormatter = new GraphFormatter( $this->options );
148
		$graphFormatter->buildGraph( $this->nodes );
149
150
		// Calls graphvizParserHook function from MediaWiki GraphViz extension
151
		$result = $GLOBALS['wgParser']->recursiveTagParse( "<graphviz>" . $graphFormatter->getGraph
152
				() . "</graphviz>" );
153
154
		// append legend
155
		$result .= $graphFormatter->getGraphLegend();
156
157
		return $result;
158
	}
159
160
	/**
161
	 * Process a result row and create SRF\GraphNodes
162
	 *
163
	 * @since 3.1
164
	 *
165
	 * @param array $row
166
	 *
167
	 */
168
	protected function processResultRow( array /* of SMWResultArray */ $row ) {
169
170
		// loop through all row fields
171
		foreach ( $row as $i => $resultArray ) {
172
173
			// loop through all values of a multivalue field
174
			while ( ( /* SMWWikiPageValue */
175
				$object = $resultArray->getNextDataValue() ) !== false ) {
176
177
				// create SRF\GraphNode for column 0
178
				if ( $i == 0 ) {
179
					$node = new GraphNode( $object->getShortWikiText() );
180
					$node->setLabel( $object->getPreferredCaption() );
181
					$this->nodes[] = $node;
182
				} else {
183
					$node->addParentNode( $resultArray->getPrintRequest()->getLabel(), $object->getShortWikiText() );
0 ignored issues
show
The variable $node 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...
184
				}
185
			}
186
		}
187
	}
188
189
	/**
190
	 * @see SMWResultPrinter::getParamDefinitions
191
	 *
192
	 * @since 1.8
193
	 *
194
	 * @param $definitions array of IParamDefinition
195
	 *
196
	 * @return array of IParamDefinition|array
197
	 */
198
	public function getParamDefinitions( array $definitions ) {
199
		$params = parent::getParamDefinitions( $definitions );
200
201
		$params['graphname'] = [
202
			'default' => 'QueryResult',
203
			'message' => 'srf-paramdesc-graphname',
204
		];
205
206
		$params['graphsize'] = [
207
			'type' => 'string',
208
			'default' => '',
209
			'message' => 'srf-paramdesc-graphsize',
210
			'manipulatedefault' => false,
211
		];
212
213
		$params['graphlegend'] = [
214
			'type' => 'boolean',
215
			'default' => false,
216
			'message' => 'srf-paramdesc-graphlegend',
217
		];
218
219
		$params['graphlabel'] = [
220
			'type' => 'boolean',
221
			'default' => false,
222
			'message' => 'srf-paramdesc-graphlabel',
223
		];
224
225
		$params['graphlink'] = [
226
			'type' => 'boolean',
227
			'default' => false,
228
			'message' => 'srf-paramdesc-graphlink',
229
		];
230
231
		$params['graphcolor'] = [
232
			'type' => 'boolean',
233
			'default' => false,
234
			'message' => 'srf-paramdesc-graphcolor',
235
		];
236
237
		$params['arrowdirection'] = [
238
			'aliases' => 'rankdir',
239
			'default' => 'LR',
240
			'message' => 'srf-paramdesc-rankdir',
241
			'values'  => [ 'LR', 'RL', 'TB', 'BT' ],
242
		];
243
244
		$params['arrowhead'] = [
245
			'default' => 'normal',
246
			'message' => 'srf-paramdesc-arrowhead',
247
			'values' => self::$ARROW_SHAPES,
248
		];
249
250
		$params['nodeshape'] = [
251
			'default' => false,
252
			'message' => 'srf-paramdesc-graph-nodeshape',
253
			'manipulatedefault' => false,
254
			'values' => self::$NODE_SHAPES,
255
		];
256
257
		$params['relation'] = [
258
			'default' => 'child',
259
			'message' => 'srf-paramdesc-graph-relation',
260
			'manipulatedefault' => false,
261
			'values' => [ 'parent', 'child' ],
262
		];
263
264
		$params['wordwraplimit'] = [
265
			'type' => 'integer',
266
			'default' => 25,
267
			'message' => 'srf-paramdesc-graph-wwl',
268
			'manipulatedefault' => false,
269
		];
270
271
		$params['nodelabel'] = [
272
			'default' => '',
273
			'message' => 'srf-paramdesc-nodelabel',
274
			'values' => self::$NODE_LABELS,
275
		];
276
277
		return $params;
278
	}
279
}
280