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.

formats/tree/TreeNodeVisitor.php (1 issue)

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\Formats\Tree;
4
5
use Tree\Node\NodeInterface;
6
use Tree\Visitor\Visitor;
7
8
class TreeNodePrinter implements Visitor {
9
10
	private $depth = 0;
11
	private $rowNumber = 0;
12
	private $configuration = null;
13
	/**
14
	 * @var TreeResultPrinter
15
	 */
16
	private $resultPrinter = null;
17
	private $columnLabels = [];
18
19 5
	public function __construct( TreeResultPrinter $resultPrinter, $configuration ) {
20 5
		$this->configuration = $configuration;
21 5
		$this->resultPrinter = $resultPrinter;
22 5
	}
23
24 5
	public function visit( NodeInterface $node ) {
25
26 5
		$nodeTexts = [ $this->getTextForNode( $node ) ];
0 ignored issues
show
$node of type object<Tree\Node\NodeInterface> is not a sub-type of object<SRF\Formats\Tree\TreeNode>. It seems like you assume a concrete implementation of the interface Tree\Node\NodeInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
27
28 5
		$this->depth++;
29 5
		$this->rowNumber++;
30
31 5
		foreach ( $node->getChildren() as $child ) {
32 5
			$nodeTexts = array_merge(
33 5
				$nodeTexts,
34 5
				$child->accept( $this )
35
			);
36
		}
37
38 5
		$this->depth--;
39
40 5
		return $nodeTexts;
41
	}
42
43 5
	protected function getTextForNode( TreeNode $node ) {
44
45
		/** @var \SMWResultArray[]|null $row */
46 5
		$row = $node->getValue();
47
48 5
		if ( $row === null ) {
49 5
			return '';
50
		}
51
52 5
		$textForNode = str_repeat( ( $this->configuration['format'] === 'oltree' ) ? '#' : '*', $this->depth );
53
54 5
		if ( $this->configuration['template'] === '' ) {
55
			// build simple list
56 5
			$textForNode .= $this->getTextForRowNoTemplate( $row );
57
		} else {
58
			// build template code
59 3
			$textForNode .= $this->getTextForRowWithTemplate( $row );
60
61
		}
62
63 5
		return $textForNode;
64
	}
65
66
	/**
67
	 * @param \SMWResultArray[] $row
68
	 *
69
	 * @return string
70
	 */
71 5
	protected function getTextForRowNoTemplate( $row ) {
72
73 5
		$cellTexts = [];
74 5
		foreach ( $row as $columnNumber => $cell ) {
75
76 5
			$valuesText = $this->getValuesTextForCell( $cell, $columnNumber );
77
78 5
			if ( $valuesText === '' ) {
79 1
				continue;
80
			}
81
82 5
			$labelText = $this->getLabelForCell( $cell, $columnNumber );
83
84 5
			$cellTexts[] = $labelText . $valuesText;
85
		}
86
87 5
		if ( count( $cellTexts ) > 0 ) {
88 5
			$result = array_shift( $cellTexts );
89
90 5
			if ( count( $cellTexts ) > 0 ) {
91 5
				$result .= ' (' . join( $this->configuration['sep'], $cellTexts ) . ')';
92
			}
93
94
		} else {
95
			$result = '';
96
		}
97
98 5
		return $result;
99
	}
100
101
	/**
102
	 * @param \SMWResultArray[] $row
103
	 *
104
	 * @return string
105
	 */
106 3
	protected function getTextForRowWithTemplate( $row ) {
107
108 3
		$templateParams = [];
109 3
		foreach ( $row as $columnNumber => $cell ) {
110
111 3
			$valuesText = $this->getValuesTextForCell( $cell, $columnNumber );
112 3
			$paramName = $this->getParamNameForCell( $cell, $columnNumber );
113
114 3
			$templateParams[] = "$paramName=$valuesText ";
115
		}
116
117 3
		$templateParams[] = "#=$this->rowNumber ";
118
119 3
		return $this->resultPrinter->getTemplateCall( $this->configuration['template'], $templateParams );
120
	}
121
122
	/**
123
	 * @param \SMWResultArray $cell
124
	 * @param int $columnNumber
125
	 *
126
	 * @return string
127
	 */
128 5
	protected function getValuesTextForCell( \SMWResultArray $cell, $columnNumber ) {
129
130 5
		$cell->reset();
131 5
		$linker = $this->resultPrinter->getLinkerForColumn( $columnNumber );
132
133 5
		$valueTexts = [];
134
135 5
		while ( ( $text = $cell->getNextText( SMW_OUTPUT_WIKI, $linker ) ) !== false ) {
136 5
			$valueTexts[] = $text;
137
		}
138
139 5
		$valuesText = join( $this->configuration['sep'], $valueTexts );
140 5
		return $valuesText;
141
	}
142
143
	/**
144
	 * @param \SMWResultArray $cell
145
	 * @param int $columnNumber
146
	 *
147
	 * @return string
148
	 */
149 3
	protected function getParamNameForCell( $cell, $columnNumber ) {
150
151 3
		if ( !array_key_exists( $columnNumber, $this->columnLabels ) ) {
152
153 3
			$label = $cell->getPrintRequest()->getLabel();
154
155 3
			if ( $this->configuration[ 'named args' ] === true || ( $label === '' ) ) {
156 3
				$paramName = $columnNumber + 1;
157
			} else {
158 1
				$paramName = $label;
159
			}
160
161 3
			$this->columnLabels[$columnNumber] = $paramName;
162
		}
163
164 3
		return $this->columnLabels[$columnNumber];
165
	}
166
167
	/**
168
	 * @param \SMWResultArray $cell
169
	 *
170
	 * @return string
171
	 */
172 5
	protected function getLabelForCell( $cell, $columnNumber ) {
173
174 5
		if ( !array_key_exists( $columnNumber, $this->columnLabels ) ) {
175
176 5
			if ( $this->configuration['headers'] === 'hide' || $cell->getPrintRequest()->getLabel() === '' ) {
177 5
				$labelText = '';
178 1
			} elseif ( $this->configuration['headers'] === 'plain' ) {
179
				$labelText = $cell->getPrintRequest()->getText( SMW_OUTPUT_WIKI ) . ': ';
180
			} else { // $this->configuration[ 'headers' ] === 'link'
181 1
				$labelText = $cell->getPrintRequest()->getText(
182 1
						SMW_OUTPUT_WIKI,
183 1
						$this->resultPrinter->getLinker()
184 1
					) . ': ';
185
			}
186
187 5
			$this->columnLabels[$columnNumber] = $labelText;
188
		}
189
190 5
		return $this->columnLabels[$columnNumber];
191
	}
192
193
}
194