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'); } }