Skip to content

Commit 4273b54

Browse files
committed
Add blacklist file to reject some IPFS files
1 parent c4c01c9 commit 4273b54

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

www/blacklist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
QmYkAyjWg7PzgM8kmTadBSu58ab75vHNT39bivHUiBEzdE

www/src/config.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
const REDIRECT_TEMPLATE = '/redirect.template.html';
3232
const NOTFOUND_TEMPLATE = '/notfound.template.html';
3333
const PROXY_LIST_FILE = 'gateway.txt';
34+
const BLACKLIST_LIST_FILE = 'blacklist.txt';
3435
const CHECK_HOST_TIMEOUT = 3;
3536
const IPFS_CHECK_HOST_URI = 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme';
3637
const IPFS_CHECK_HOST_VERIFY_STRING = 'Welcome to IPFS';

www/src/ipfsProxyHTTP.class.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public static function loadInstance($uri) {
8888
*/
8989
public function dispatch() {
9090
if ($this->uri) {
91+
if ($this->isBlacklisted($this->uri))
92+
return self::notFound();
93+
9194
foreach(IPFS_STRING_PREFIX as $prefix)
9295
if (strtolower(substr($this->uri, 0, strlen($prefix))) == $prefix) {
9396
$this->ipfs_uri = substr($this->uri, strlen($prefix) + 1);
@@ -353,4 +356,27 @@ public function setSSLverifyPeer($bool) {
353356

354357
return $this;
355358
}
359+
360+
/**
361+
* Check if URL is blacklisted
362+
*
363+
* @param $url URL to check
364+
* @return bool
365+
*/
366+
public function isBlacklisted($url) {
367+
if (!file_exists(BLACKLIST_LIST_FILE))
368+
return false;
369+
370+
if (!is_readable(BLACKLIST_LIST_FILE))
371+
self::error('Blacklist file is not readable');
372+
373+
$blacklists = file(BLACKLIST_LIST_FILE, FILE_IGNORE_NEW_LINES );
374+
375+
foreach ($blacklists as $b)
376+
if (stripos($url, $b) !== FALSE)
377+
return true;
378+
379+
380+
return false;
381+
}
356382
}

0 commit comments

Comments
 (0)