2017-11-10 17:02:59 +00:00
|
|
|
<?php
|
2017-11-17 01:51:03 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-11-10 17:02:59 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
namespace JKingWeb\Arsse\REST\TinyTinyRSS;
|
|
|
|
|
|
|
|
use JKingWeb\Arsse\Arsse;
|
|
|
|
use JKingWeb\Arsse\REST\Response;
|
|
|
|
|
|
|
|
class Icon extends \JKingWeb\Arsse\REST\AbstractHandler {
|
|
|
|
public function __construct() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dispatch(\JKingWeb\Arsse\REST\Request $req): Response {
|
|
|
|
if ($req->method != "GET") {
|
|
|
|
// only GET requests are allowed
|
|
|
|
return new Response(405, "", "", ["Allow: GET"]);
|
|
|
|
} elseif (!preg_match("<^(\d+)\.ico$>", $req->url, $match) || !((int) $match[1])) {
|
|
|
|
return new Response(404);
|
|
|
|
}
|
|
|
|
$url = Arsse::$db->subscriptionFavicon((int) $match[1]);
|
|
|
|
if ($url) {
|
|
|
|
// strip out anything after literal line-end characters; this is to mitigate a potential header (e.g. cookie) injection from the URL
|
2017-11-30 03:42:50 +00:00
|
|
|
if (($pos = strpos($url, "\r")) !== false || ($pos = strpos($url, "\n")) !== false) {
|
2017-11-10 17:02:59 +00:00
|
|
|
$url = substr($url, 0, $pos);
|
|
|
|
}
|
|
|
|
return new Response(301, "", "", ["Location: $url"]);
|
|
|
|
} else {
|
|
|
|
return new Response(404);
|
|
|
|
}
|
|
|
|
}
|
2017-11-30 03:42:50 +00:00
|
|
|
}
|