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/filtered/src/View/CalendarView.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\Filtered\View;
4
5
/**
6
 * File holding the CalendarView class
7
 *
8
 * @author Stephan Gambke
9
 * @file
10
 * @ingroup SemanticResultFormats
11
 */
12
13
use Message;
14
use SRF\Filtered\ResultItem;
15
16
/**
17
 * The CalendarView class defines the List view.
18
 *
19
 * Available parameters for this view:
20
 *   list view type: list|ul|ol; default: list
21
 *   list view template: a template rendering a list item
22
 *   list view introtemplate: a template prepended to the list
23
 *   list view outrotemplate: a template appended to the list
24
 *   list view named args: use named args for templates
25
 *
26
 * @ingroup SemanticResultFormats
27
 */
28
class CalendarView extends View {
29
30
	private $start;
31
	private $end;
32
	private $title;
33
	private $titleTemplate;
34
35
	/**
36
	 * @param ResultItem $row
37
	 *
38
	 * @return array
39
	 */
40 1
	public function getJsDataForRow( ResultItem $row ) {
41
42 1
		$value = $row->getValue();
43 1
		$data = [];
44 1
		$wikitext = '';
45
46 1
		foreach ( $value as $valueId => $field ) {
47
48 1
			$printRequest = $field->getPrintRequest();
49
50 1
			$field->reset();
51 1
			$datavalue = $field->getNextDataValue();
52
53 1
			if ( $datavalue instanceof \SMWTimeValue &&
54
				( $printRequest->getLabel() === $this->start || $this->start === null && !array_key_exists(
55 1
						'start',
56
						$data
57
					) )
58
			) {
59
				// found specified column for start date
60
				// OR no column for start date specified, take first available date value
61
				$data['start'] = $datavalue->getISO8601Date();
62
			}
63
64 1
			if ( $datavalue instanceof \SMWTimeValue && $printRequest->getLabel() === $this->end ) {
65
				// found specified column for end date
66
				$data['end'] = $datavalue->getISO8601Date();
67
			}
68
69 1
			if ( $this->titleTemplate === null &&
70 1
				( $printRequest->getLabel() === $this->title || $this->title === null && !array_key_exists(
71 1
						'title',
72
						$data
73
					) )
74
			) {
75
				// found specified column for title
76 1
				if ( $datavalue !== false ) {
77 1
					if ( $datavalue instanceof \SMWWikiPageValue ) {
78 1
						$data['url'] = $datavalue->getDataItem()->getTitle()->getLocalURL();
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class SMWDataItem as the method getTitle() does only exist in the following sub-classes of SMWDataItem: SMWDIWikiPage, SMW\DIWikiPage. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
79
					}
80 1
					$data['title'] = $datavalue->getShortHTMLText();
81
				}
82
			}
83
84
			// only add to title template if requested and if not hidden
85 1
			if ( $this->titleTemplate !== null && filter_var(
86
					$printRequest->getParameter( 'hide' ),
87
					FILTER_VALIDATE_BOOLEAN
88 1
				) === false ) {
89
90
				$params = [];
91
				while ( ( $text = $field->getNextText(
92
						SMW_OUTPUT_WIKI,
93
						$this->getQueryPrinter()->getLinker( $valueId === 0 )
94
					) ) !== false ) {
95
					$params[] = $text;
96
				}
97
				$wikitext .= '|' . ( $valueId + 1 ) . '=' . join( ',', $params );
98
			}
99
100
		}
101
102
		// only add to title template if requested and if not hidden
103 1
		if ( $this->titleTemplate !== null ) {
104
//			$wikitext .= "|#=$rownum";
105
			$data['title'] = trim(
106
				$this->getQueryPrinter()->getParser()->recursiveTagParse(
107
					'{{' . $this->titleTemplate . $wikitext . '}}'
108
				)
109
			);
110
			$this->getQueryPrinter()->getParser()->replaceLinkHolders( $data['title'] );
111
		}
112
113 1
		return $data;
114
	}
115
116
	/**
117
	 * Transfers the parameters applicable to this view into internal variables.
118
	 */
119
	protected function handleParameters() {
120
121
		$params = $this->getActualParameters();
122
		$parser = $this->getQueryPrinter()->getParser();
123
124
		// find the hash for the printout containing the start date
125
		if ( $params['calendar view start'] !== '' ) {
126
			$this->start = trim( $parser->recursiveTagParse( $params['calendar view start'] ) );
127
		}
128
129
		// find the hash for the printout containing the start date
130
		if ( $params['calendar view end'] !== '' ) {
131
			$this->end = trim( $parser->recursiveTagParse( $params['calendar view end'] ) );
132
		}
133
134
		// find the hash for the printout containing the title of the element
135
		if ( $params['calendar view title'] !== '' ) {
136
			$this->title = trim( $parser->recursiveTagParse( $params['calendar view title'] ) );
137
		}
138
139
		// find the hash for the printout containing the title of the element
140
		if ( $params['calendar view title template'] !== '' ) {
141
			$this->titleTemplate = trim( $parser->recursiveTagParse( $params['calendar view title template'] ) );
142
		}
143
144
//		$this->mTemplate = $params['list view template'];
145
//		$this->mIntroTemplate = $params['list view introtemplate'];
146
//		$this->mOutroTemplate = $params['list view outrotemplate'];
147
//		$this->mNamedArgs = $params['list view named args'];
148
//
149
//		if ( $params['headers'] == 'hide' ) {
150
//			$this->mShowHeaders = SMW_HEADERS_HIDE;
151
//		} elseif ( $params['headers'] == 'plain' ) {
152
//			$this->mShowHeaders = SMW_HEADERS_PLAIN;
153
//		} else {
154
//			$this->mShowHeaders = SMW_HEADERS_SHOW;
155
//		}
156
	}
157
158
	/**
159
	 * A function to describe the allowed parameters of a query for this view.
160
	 *
161
	 * @return array of Parameter
162
	 */
163 2
	public static function getParameters() {
164 2
		$params = parent::getParameters();
165
166 2
		$params[] = [
167
			// 'type' => 'string',
168
			'name' => 'calendar view start',
169
			'message' => 'srf-paramdesc-filtered-calendar-start',
170
			'default' => '',
171
			// 'islist' => false,
172
		];
173
174 2
		$params[] = [
175
			// 'type' => 'string',
176
			'name' => 'calendar view end',
177
			'message' => 'srf-paramdesc-filtered-calendar-end',
178
			'default' => '',
179
			// 'islist' => false,
180
		];
181
182 2
		$params[] = [
183
			// 'type' => 'string',
184
			'name' => 'calendar view title',
185
			'message' => 'srf-paramdesc-filtered-calendar-title',
186
			'default' => '',
187
			// 'islist' => false,
188
		];
189
190 2
		$params[] = [
191
			// 'type' => 'string',
192
			'name' => 'calendar view title template',
193
			'message' => 'srf-paramdesc-filtered-calendar-title-template',
194
			'default' => '',
195
			// 'islist' => false,
196
		];
197
198 2
		return $params;
199
	}
200
201
	/**
202
	 * Returns the name of the resource module to load for this view.
203
	 *
204
	 * @return string|array
205
	 */
206 1
	public function getResourceModules() {
207 1
		return 'ext.srf.filtered.calendar-view';
208
	}
209
210
	/**
211
	 * Returns an array of config data for this filter to be stored in the JS
212
	 *
213
	 * @return string[]
214
	 */
215 1
	public function getJsConfig() {
216 1
		global $wgAmericanDates;
217
218
		return
219 1
			$this->getParamHashes( $this->getQueryResults(), $this->getActualParameters() ) +
220
			[
221 1
				'firstDay' => ( $wgAmericanDates ? '0' : Message::newFromKey(
222 1
					'srf-filtered-firstdayofweek'
223 1
				)->inContentLanguage()->text() ),
224 1
				'isRTL' => wfGetLangObj( true )->isRTL(),
225
			];
226
	}
227
228
	/**
229
	 * @param ResultItem[] $results
230
	 * @param string[] $params
231
	 *
232
	 * @return string[]
233
	 */
234 1
	private function getParamHashes( $results, $params ) {
235
236 1
		if ( $results === null || count( $results ) < 1 ) {
237
			return [];
238
		}
239
240 1
		if ( $params['calendar view title'] !== '' ) {
241
242
			$titleLabel = trim(
243
				$this->getQueryPrinter()->getParser()->recursiveTagParse( $params['calendar view title'] )
244
			);
245
246
			// find the hash for the printout containing the title of the element
247
			foreach ( reset( $results )->getValue() as $printout ) {
248
249
				if ( $printout->getPrintRequest()->getLabel() === $titleLabel ) {
250
					return [ 'title' => $this->getQueryPrinter()->uniqid( $printout->getPrintRequest()->getHash() ) ];
251
				}
252
			}
253
254 1
		} elseif ( $params['mainlabel'] !== '-' ) { // first column not suppressed
255 1
			$value = reset( $results )->getValue();
256 1
			return [ 'title' => $this->getQueryPrinter()->uniqid( reset( $value )->getPrintRequest()->getHash() ) ];
257
		}
258
259
		return [];
260
	}
261
262
	/**
263
	 * Returns the label of the selector for this view.
264
	 *
265
	 * @return String the selector label
266
	 */
267
	public function getSelectorLabel() {
268
		return Message::newFromKey( 'srf-filtered-selectorlabel-calendar' )->inContentLanguage()->text();
269
	}
270
271
}
272