mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-05-24 08:14:56 -04:00
SimplePie prevent cache pollution (#3502)
* SimplePie prevent cache polution #fix https://github.com/FreshRSS/FreshRSS/pull/3367#issuecomment-766250249 #fix https://github.com/FreshRSS/FreshRSS/pull/3494#issuecomment-790113663 * Fix bug * Minor improvement * Update cache filename in FreshRSS (1/2) * cacheFilename temp * New SimplePie get_cache_filename() * Fix typos * Update lib/SimplePie/SimplePie.php Typo * Include user-agent and timeout * fix array_merge * Declaration * force_feed was lost in a commit
This commit is contained in:
committed by
GitHub
parent
ef4a826e34
commit
b7fdfbb894
@@ -497,7 +497,9 @@ class FreshRSS_Feed extends Minz_Model {
|
||||
}
|
||||
|
||||
protected function cacheFilename() {
|
||||
return CACHE_PATH . '/' . md5($this->url) . '.spc';
|
||||
$simplePie = customSimplePie($this->attributes());
|
||||
$filename = $simplePie->get_cache_filename($this->url);
|
||||
return CACHE_PATH . '/' . $filename . '.spc';
|
||||
}
|
||||
|
||||
public function clearCache() {
|
||||
|
||||
@@ -920,6 +920,37 @@ class SimplePie
|
||||
$this->cache_location = (string) $location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filename (i.e. hash, without path and without extension) of the file to cache a given URL.
|
||||
*/
|
||||
public function get_cache_filename($url)
|
||||
{
|
||||
// Append custom parameters to the URL to avoid cache pollution in case of multiple calls with different parameters.
|
||||
$url .= $this->force_feed ? '#force_feed' : '';
|
||||
$options = array();
|
||||
if ($this->timeout != 10)
|
||||
{
|
||||
$options[CURLOPT_TIMEOUT] = $this->timeout;
|
||||
}
|
||||
if ($this->useragent !== SIMPLEPIE_USERAGENT)
|
||||
{
|
||||
$options[CURLOPT_USERAGENT] = $this->useragent;
|
||||
}
|
||||
if (!empty($this->curl_options))
|
||||
{
|
||||
foreach ($this->curl_options as $k => $v)
|
||||
{
|
||||
$options[$k] = $v;
|
||||
}
|
||||
}
|
||||
if (!empty($options))
|
||||
{
|
||||
ksort($options);
|
||||
$url .= '#' . urlencode(var_export($options, true));
|
||||
}
|
||||
return call_user_func($this->cache_name_function, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether feed items should be sorted into reverse chronological order
|
||||
*
|
||||
@@ -1429,8 +1460,8 @@ class SimplePie
|
||||
// Decide whether to enable caching
|
||||
if ($this->cache && $parsed_feed_url['scheme'] !== '')
|
||||
{
|
||||
$url = $this->feed_url . ($this->force_feed ? '#force_feed' : '');
|
||||
$cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, call_user_func($this->cache_name_function, $url), 'spc'));
|
||||
$filename = $this->get_cache_filename($this->feed_url);
|
||||
$cache = $this->registry->call('Cache', 'get_handler', array($this->cache_location, $filename, 'spc'));
|
||||
}
|
||||
|
||||
// Fetch the data via SimplePie_File into $this->raw_data
|
||||
|
||||
@@ -173,6 +173,7 @@ function customSimplePie($attributes = array()) {
|
||||
$simplePie = new SimplePie();
|
||||
$simplePie->set_useragent(FRESHRSS_USERAGENT);
|
||||
$simplePie->set_syslog(FreshRSS_Context::$system_conf->simplepie_syslog_enabled);
|
||||
$simplePie->set_cache_name_function('sha1');
|
||||
$simplePie->set_cache_location(CACHE_PATH);
|
||||
$simplePie->set_cache_duration($limits['cache_duration']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user