Issues (2)

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/Feed.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
<?php
2
3
namespace Unicodeveloper\LaravelFeeder;
4
5
use SimpleXMLElement;
6
use Unicodeveloper\LaravelFeeder\Exceptions\FeedException;
7
8
/**
9
 * RSS for PHP - small and easy-to-use library for consuming an RSS Feed
10
 *
11
 * @author     David Grudl
12
 * @copyright  Copyright (c) 2008 David Grudl
13
 * @license    New BSD License
14
 * @link       http://phpfashion.com/
15
 * @version    1.1
16
 */
17
class Feed
18
{
19
	/** @var int */
20
	public static $cacheExpire = 86400; // 1 day
21
22
	/** @var string */
23
	public static $cacheDir;
24
25
	/** @var SimpleXMLElement */
26
	protected $xml;
27
28
	/**
29
	 * Loads RSS channel.
30
	 * @param  string  RSS feed URL
31
	 * @param  string  optional user name
32
	 * @param  string  optional password
33
	 * @return Feed
34
	 * @throws FeedException
35
	 */
36
	public static function loadRss($url, $user = NULL, $pass = NULL)
37
	{
38
		$xml = new SimpleXMLElement(self::httpRequest($url, $user, $pass), LIBXML_NOWARNING | LIBXML_NOERROR);
39
		if (!$xml->channel) {
40
			throw new FeedException('Invalid channel.');
41
		}
42
43
		self::adjustNamespaces($xml->channel);
44
45
		foreach ($xml->channel->item as $item) {
46
			// converts namespaces to dotted tags
47
			self::adjustNamespaces($item);
48
49
			// generate 'timestamp' tag
50
			if (isset($item->{'dc:date'})) {
51
				$item->timestamp = strtotime($item->{'dc:date'});
52
			} elseif (isset($item->pubDate)) {
53
				$item->timestamp = strtotime($item->pubDate);
54
			}
55
		}
56
57
		$feed = new self;
58
		$feed->xml = $xml->channel;
0 ignored issues
show
The property channel does not seem to exist in SimpleXMLElement.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
59
		return $feed;
60
	}
61
62
	/**
63
	 * Loads Atom channel.
64
	 * @param  string  Atom feed URL
65
	 * @param  string  optional user name
66
	 * @param  string  optional password
67
	 * @return Feed
68
	 * @throws FeedException
69
	 */
70
	public static function loadAtom($url, $user = NULL, $pass = NULL)
71
	{
72
		$xml = new SimpleXMLElement(self::httpRequest($url, $user, $pass), LIBXML_NOWARNING | LIBXML_NOERROR);
73
		if (!in_array('http://www.w3.org/2005/Atom', $xml->getDocNamespaces(), TRUE)) {
74
			throw new FeedException('Invalid channel.');
75
		}
76
77
		// generate 'timestamp' tag
78
		foreach ($xml->entry as $entry) {
79
			$entry->timestamp = strtotime($entry->updated);
80
		}
81
82
		$feed = new self;
83
		$feed->xml = $xml;
84
		return $feed;
85
	}
86
87
	/**
88
	 * Returns property value. Do not call directly.
89
	 * @param  string  tag name
90
	 * @return SimpleXMLElement
91
	 */
92
	public function __get($name)
93
	{
94
		return $this->xml->{$name};
95
	}
96
97
	/**
98
	 * Sets value of a property. Do not call directly.
99
	 * @param  string  property name
100
	 * @param  mixed   property value
101
	 * @return void
102
	 */
103
	public function __set($name, $value)
0 ignored issues
show
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
104
	{
105
		throw new Exception("Cannot assign to a read-only property '$name'.");
106
	}
107
108
	/**
109
	 * Converts a SimpleXMLElement into an array.
110
	 * @param  SimpleXMLElement
111
	 * @return array
112
	 */
113
	public function toArray(SimpleXMLElement $xml = NULL)
114
	{
115
		if ($xml === NULL) {
116
			$xml = $this->xml;
117
		}
118
119
		if (!$xml->children()) {
120
			return (string) $xml;
121
		}
122
123
		$arr = array();
124
		foreach ($xml->children() as $tag => $child) {
125
			if (count($xml->$tag) === 1) {
126
				$arr[$tag] = $this->toArray($child);
127
			} else {
128
				$arr[$tag][] = $this->toArray($child);
129
			}
130
		}
131
132
		return $arr;
133
	}
134
135
	/**
136
	 * Process HTTP request.
137
	 * @param  string  URL
138
	 * @param  string  user name
139
	 * @param  string  password
140
	 * @return string
141
	 * @throws FeedException
142
	 */
143
	private static function httpRequest($url, $user, $pass)
144
	{
145
		if (self::$cacheDir) {
146
			$cacheFile = self::$cacheDir . '/feed.' . md5($url) . '.xml';
147
			if (@filemtime($cacheFile) + self::$cacheExpire > time()) {
148
				return file_get_contents($cacheFile);
149
			}
150
		}
151
152
		if (extension_loaded('curl')) {
153
			$curl = curl_init();
154
			curl_setopt($curl, CURLOPT_URL, $url);
155
			if ($user !== NULL || $pass !== NULL) {
156
				curl_setopt($curl, CURLOPT_USERPWD, "$user:$pass");
157
			}
158
			curl_setopt($curl, CURLOPT_HEADER, FALSE);
159
			curl_setopt($curl, CURLOPT_TIMEOUT, 20);
160
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // no echo, just return result
161
			if (!ini_get('open_basedir')) {
162
				curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); // sometime is useful :)
163
			}
164
			$result = curl_exec($curl);
165
			$ok = curl_errno($curl) === 0 && curl_getinfo($curl, CURLINFO_HTTP_CODE) === 200;
166
167
		} elseif ($user === NULL && $pass === NULL) {
168
			$result = file_get_contents($url);
169
			$ok = is_string($result);
170
171
		} else {
172
			throw new FeedException('PHP extension CURL is not loaded.');
173
		}
174
175
		if (!$ok) {
176
			if (isset($cacheFile)) {
177
				$result = @file_get_contents($cacheFile);
178
				if (is_string($result)) {
179
					return $result;
180
				}
181
			}
182
			throw new FeedException('Cannot load channel.');
183
		}
184
185
		if (isset($cacheFile)) {
186
			file_put_contents($cacheFile, $result);
187
		}
188
189
		return $result;
190
	}
191
192
	/**
193
	 * Generates better accessible namespaced tags.
194
	 * @param  SimpleXMLElement
195
	 * @return void
196
	 */
197
	private static function adjustNamespaces($el)
198
	{
199
		foreach ($el->getNamespaces(TRUE) as $prefix => $ns) {
200
			$children = $el->children($ns);
201
			foreach ($children as $tag => $content) {
202
				$el->{$prefix . ':' . $tag} = $content;
203
			}
204
		}
205
	}
206
}
207
208