File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ QmYkAyjWg7PzgM8kmTadBSu58ab75vHNT39bivHUiBEzdE
Original file line number Diff line number Diff line change 3131const REDIRECT_TEMPLATE = '/redirect.template.html ' ;
3232const NOTFOUND_TEMPLATE = '/notfound.template.html ' ;
3333const PROXY_LIST_FILE = 'gateway.txt ' ;
34+ const BLACKLIST_LIST_FILE = 'blacklist.txt ' ;
3435const CHECK_HOST_TIMEOUT = 3 ;
3536const IPFS_CHECK_HOST_URI = 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme ' ;
3637const IPFS_CHECK_HOST_VERIFY_STRING = 'Welcome to IPFS ' ;
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments