Files
dredgegram/app/Http/Controllers/ImageProxyController.php
T
dredgy d8d4ecbe8a
linter / quality (push) Canceled after 0s
tests / ci (8.3) (push) Canceled after 0s
tests / ci (8.4) (push) Canceled after 0s
tests / ci (8.5) (push) Canceled after 0s
Initial Commit
2026-08-28 21:50:26 +10:00

36 lines
991 B
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class ImageProxyController extends Controller
{
public function show(Request $request)
{
$request->validate(['url' => 'required|url']);
$url = $request->query('url');
// Only allow proxying Instagram's own CDN domains, so this
// can't be abused as an open proxy for arbitrary URLs.
$host = parse_url($url, PHP_URL_HOST);
if (! $host || ! str_ends_with($host, 'fbcdn.net') && ! str_ends_with($host, 'cdninstagram.com')) {
abort(403);
}
$response = Http::withHeaders([
'User-Agent' => 'Mozilla/5.0',
])->get($url);
if (! $response->successful()) {
abort(404);
}
return response($response->body())
->header('Content-Type', $response->header('Content-Type'))
->header('Cache-Control', 'public, max-age=3600');
}
}