GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (115)

Security Analysis    no request data  

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/extensions/BlocksSiteTreeExtension.php (13 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 SheaDawson\Blocks\Extensions;
4
5
use SheaDawson\Blocks\Model\Block;
6
use SheaDawson\Blocks\Model\Blockset;
7
use SheaDawson\Blocks\BlockManager;
8
use SheaDawson\Blocks\Forms\GridFieldConfigBlockManager;
9
use SilverStripe\CMS\Model\SiteTreeExtension;
10
use SilverStripe\Forms\ReadonlyField;
11
use SilverStripe\Forms\CheckboxField;
12
use SilverStripe\Forms\FieldList;
13
use SilverStripe\Forms\LiteralField;
14
use SilverStripe\Forms\ListboxField;
15
use SilverStripe\Forms\Tab;
16
use SilverStripe\Forms\GridField\GridField;
17
use SilverStripe\View\SSViewer;
18
use SilverStripe\ORM\ArrayList;
19
use SilverStripe\Security\Permission;
20
use SilverStripe\Control\Controller;
21
use SilverStripeAustralia\GridFieldExtensions\GridFieldOrderableRows;
22
23
/**
24
 * BlocksSiteTreeExtension.
25
 *
26
 * @author Shea Dawson <[email protected]>
27
 */
28
class BlocksSiteTreeExtension extends SiteTreeExtension
29
{
30
	private static $db = [
0 ignored issues
show
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
31
		'InheritBlockSets' => 'Boolean',
32
	];
33
34
	private static $many_many = [
0 ignored issues
show
The property $many_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
35
		"Blocks" => Block::class,
36
		"DisabledBlocks" => Block::class,
37
	];
38
39
	public static $many_many_extraFields = [
40
		'Blocks' => [
41
			'Sort' => 'Int',
42
			'BlockArea' => 'Varchar',
43
		],
44
	];
45
46
	private static $defaults = [
0 ignored issues
show
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
47
		'InheritBlockSets' => 1,
48
	];
49
50
	private static $dependencies = [
0 ignored issues
show
The property $dependencies is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
51
		'blockManager' => '%$blockManager',
52
	];
53
54
	public $blockManager;
55
56
57
	/**
58
	 * Check if the Blocks CMSFields should be displayed for this Page
59
	 *
60
	 * @return boolean
61
	 **/
62
	public function showBlocksFields()
63
	{
64
		$whiteList = $this->blockManager->getWhiteListedPageTypes();
65
		$blackList = $this->blockManager->getBlackListedPageTypes();
66
67
		if (in_array($this->owner->ClassName, $blackList)) {
68
			return false;
69
		}
70
71
		if (count($whiteList) && !in_array($this->owner->ClassName, $whiteList)) {
72
			return false;
73
		}
74
75
		if (!Permission::check('BLOCK_EDIT')) {
76
			return false;
77
		}
78
79
		return true;
80
	}
81
82
	/**
83
	 * Block manager for Pages.
84
	 * */
85
	public function updateCMSFields(FieldList $fields)
86
	{
87
		if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) {
88
			return;
89
		}
90
91
		$areas = $this->blockManager->getAreasForPageType($this->owner->ClassName);
92
93
		if ($areas && count($areas)) {
94
			$fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME', 'Blocks')));
95
			if (BlockManager::config()->get('block_area_preview')) {
96
				$fields->addFieldToTab('Root.Blocks',
97
						LiteralField::create('PreviewLink', $this->areasPreviewButton()));
98
			}
99
100
			// Blocks related directly to this Page
101
			$gridConfig = GridFieldConfigBlockManager::create(true, true, true, true)
102
				->addExisting($this->owner->class)
0 ignored issues
show
The call to GridFieldConfigBlockManager::addExisting() has too many arguments starting with $this->owner->class.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
103
				//->addBulkEditing()
104
				// ->addComponent(new GridFieldOrderableRows()) // Comment until below TODO is complete.
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
105
				;
106
107
108
			// TODO it seems this sort is not being applied...
109
			$gridSource = $this->owner->Blocks();
110
				// ->sort(array(
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
111
				// 	"FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '',
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
112
				// 	'SiteTree_Blocks.Sort' => 'ASC',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
113
				// 	'Name' => 'ASC'
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
114
				// ));
115
116
			$fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig));
117
118
119
			// Blocks inherited from BlockSets
120
			if ($this->blockManager->getUseBlockSets()) {
121
				$inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true);
122
123
				if ($inheritedBlocks->count()) {
124
					$activeInherited = $this->getBlocksFromAppliedBlockSets(null, false);
125
126
					if ($activeInherited->count()) {
127
						$fields->addFieldsToTab('Root.Blocks', [
128
							GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited,
129
								GridFieldConfigBlockManager::create(false, false, false)),
130
							LiteralField::create('InheritedBlockListTip', "<p class='message'>"._t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', ['link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>']).'<p>'),
131
						]);
132
					}
133
134
					$fields->addFieldToTab('Root.Blocks',
135
							ListboxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'),
136
									$inheritedBlocks->map('ID', 'Title'), null, null, true)
137
									->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.'))
138
					);
139
				} else {
140
					$fields->addFieldToTab('Root.Blocks',
141
							ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'),
142
									_t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable','This page has no inherited blocks to disable.')));
143
				}
144
145
				$fields->addFieldToTab('Root.Blocks',
146
					CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets')));
147
			}
148
		}
149
	}
150
151
	/**
152
	 * Called from templates to get rendered blocks for the given area.
153
	 *
154
	 * @param string $area
155
	 * @param int    $limit Limit the items to this number, or null for no limit
156
	 */
157
	public function BlockArea($area, $limit = null)
0 ignored issues
show
BlockArea uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
158
	{
159
		if ($this->owner->ID <= 0) {
160
			return;
161
		} // blocks break on fake pages ie Security/login
162
163
		$list = $this->getBlockList($area);
164
165
		foreach ($list as $block) {
166
			if (!$block->canView()) {
167
				$list->remove($block);
168
			}
169
		}
170
171
		if ($limit !== null) {
172
			$list = $list->limit($limit);
173
		}
174
175
		$data = [];
176
		$data['HasBlockArea'] = ($this->owner->canEdit() && isset($_REQUEST['block_preview']) && $_REQUEST['block_preview']) || $list->Count() > 0;
177
		$data['BlockArea'] = $list;
178
		$data['AreaID'] = $area;
179
180
		$data = $this->owner->customise($data);
181
182
		$template = ['BlockArea_'.$area];
183
184
		if (SSViewer::hasTemplate($template)) {
185
			return $data->renderWith($template);
186
		} else {
187
			return $data->renderWith('BlockArea');
188
		}
189
	}
190
191
	public function HasBlockArea($area)
0 ignored issues
show
HasBlockArea uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

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

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
192
	{
193
		if ($this->owner->canEdit() && isset($_REQUEST['block_preview']) && $_REQUEST['block_preview']) {
194
			return true;
195
		}
196
197
		$list = $this->getBlockList($area);
198
199
		foreach ($list as $block) {
200
			if (!$block->canView()) {
201
				$list->remove($block);
202
			}
203
		}
204
205
		return $list->Count() > 0;
206
	}
207
208
	/**
209
	 * Get a merged list of all blocks on this page and ones inherited from BlockSets.
210
	 *
211
	 * @param string|null $area            filter by block area
212
	 * @param bool        $includeDisabled Include blocks that have been explicitly excluded from this page
213
	 *                                     i.e. blocks from block sets added to the "disable inherited blocks" list
214
	 *
215
	 * @return ArrayList
216
	 * */
217
	public function getBlockList($area = null, $includeDisabled = false)
218
	{
219
		$includeSets = $this->blockManager->getUseBlockSets() && $this->owner->InheritBlockSets;
220
		$blocks = ArrayList::create();
221
222
		// get blocks directly linked to this page
223
		$nativeBlocks = $this->owner->Blocks()->sort('Sort');
224
		if ($area) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $area of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
225
			$nativeBlocks = $nativeBlocks->filter('BlockArea', $area);
226
		}
227
228
		if ($nativeBlocks->count()) {
229
			foreach ($nativeBlocks as $block) {
230
				$blocks->add($block);
231
			}
232
		}
233
234
		// get blocks from BlockSets
235
		if ($includeSets) {
236
			$blocksFromSets = $this->getBlocksFromAppliedBlockSets($area, $includeDisabled);
237
			if ($blocksFromSets->count()) {
238
				// merge set sources
239
				foreach ($blocksFromSets as $block) {
240
					if (!$blocks->find('ID', $block->ID)) {
241
						if ($block->AboveOrBelow == 'Above') {
242
							$blocks->unshift($block);
243
						} else {
244
							$blocks->push($block);
245
						}
246
					}
247
				}
248
			}
249
		}
250
251
		return $blocks;
252
	}
253
254
	/**
255
	 * Get Any BlockSets that apply to this page.
256
	 *
257
	 * @return ArrayList
258
	 * */
259
	public function getAppliedSets()
260
	{
261
		$list = ArrayList::create();
262
		if (!$this->owner->InheritBlockSets) {
263
			return $list;
264
		}
265
266
		$sets = BlockSet::get()->where("(PageTypesValue IS NULL) OR (PageTypesValue LIKE '%:\"{$this->owner->ClassName}%')");
267
		$ancestors = $this->owner->getAncestors()->column('ID');
268
269
		foreach ($sets as $set) {
270
			$restrictedToParerentIDs = $set->PageParents()->column('ID');
271
			if (count($restrictedToParerentIDs)) {
272
				// check whether the set should include selected parent, in which case check whether
273
				// it was in the restricted parents list. If it's not, or if include parentpage
274
				// wasn't selected, we check the ancestors of this page.
275
				if ($set->IncludePageParent && in_array($this->owner->ID, $restrictedToParerentIDs)) {
276
					$list->add($set);
277
				} else {
278
					if (count($ancestors)) {
279
						foreach ($ancestors as $ancestor) {
280
							if (in_array($ancestor, $restrictedToParerentIDs)) {
281
								$list->add($set);
282
								continue;
283
							}
284
						}
285
					}
286
				}
287
			} else {
288
				$list->add($set);
289
			}
290
		}
291
292
		return $list;
293
	}
294
295
	/**
296
	 * Get all Blocks from BlockSets that apply to this page.
297
	 *
298
	 * @return ArrayList
299
	 * */
300
	public function getBlocksFromAppliedBlockSets($area = null, $includeDisabled = false)
301
	{
302
		$blocks = ArrayList::create();
303
		$sets = $this->getAppliedSets();
304
305
		if (!$sets->count()) {
306
			return $blocks;
307
		}
308
309
		foreach ($sets as $set) {
310
			$setBlocks = $set->Blocks()->sort('Sort DESC');
311
312
			if (!$includeDisabled) {
313
				$setBlocks = $setBlocks->exclude('ID', $this->owner->DisabledBlocks()->column('ID'));
314
			}
315
316
			if ($area) {
317
				$setBlocks = $setBlocks->filter('BlockArea', $area);
318
			}
319
320
			$blocks->merge($setBlocks);
321
		}
322
323
		$blocks->removeDuplicates();
324
325
		return $blocks;
326
	}
327
328
	/**
329
	 * Get's the link for a block area preview button.
330
	 *
331
	 * @return string
332
	 * */
333
	public function areasPreviewLink()
334
	{
335
		return Controller::join_links($this->owner->Link(), '?block_preview=1');
336
	}
337
338
	/**
339
	 * Get's html for a block area preview button.
340
	 *
341
	 * @return string
342
	 * */
343
	public function areasPreviewButton()
344
	{
345
		return "<a class='btn btn-primary' style='font-style:normal;' href='".$this->areasPreviewLink()."' target='_blank'>"._t('BlocksSiteTreeExtension.PreviewBlockAreasLink', 'Preview Block Areas for this page').'</a>';
346
	}
347
}
348