From 3118f02d2ad6e458e29c7a2e7abe88ec14af9109 Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:18:23 +0200 Subject: [PATCH] Ignore invalid cookies supplied by YouTube (#765) --- YoutubeExplode/YoutubeHttpHandler.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/YoutubeExplode/YoutubeHttpHandler.cs b/YoutubeExplode/YoutubeHttpHandler.cs index f9903e29..39c2e346 100644 --- a/YoutubeExplode/YoutubeHttpHandler.cs +++ b/YoutubeExplode/YoutubeHttpHandler.cs @@ -153,7 +153,20 @@ private HttpResponseMessage HandleResponse(HttpResponseMessage response) if (response.Headers.TryGetValues("Set-Cookie", out var cookieHeaderValues)) { foreach (var cookieHeaderValue in cookieHeaderValues) - _cookieContainer.SetCookies(response.RequestMessage.RequestUri, cookieHeaderValue); + { + try + { + _cookieContainer.SetCookies( + response.RequestMessage.RequestUri, + cookieHeaderValue + ); + } + catch (CookieException) + { + // YouTube may send cookies for other domains, ignore them + // https://github.com/Tyrrrz/YoutubeExplode/issues/762 + } + } } return response;