Skip to content

Commit

Permalink
core: fix errors removing old cookies (#13420)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngosang committed Jul 31, 2022
1 parent 33093d6 commit 77bd826
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Jackett.Common/Utils/CookieUtil.cs
Expand Up @@ -5,11 +5,14 @@
using System.Net;
using System.Reflection;
using System.Text.RegularExpressions;
using NLog;

namespace Jackett.Common.Utils
{
public static class CookieUtil
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
// NOTE: we are not checking non-ascii characters and we should
private static readonly Regex _CookieRegex = new Regex(@"([^\(\)<>@,;:\\""/\[\]\?=\{\}\s]+)=([^,;\\""\s]+)");
Expand Down Expand Up @@ -52,12 +55,17 @@ public static void RemoveAllCookies(CookieContainer cookieJar)
.InvokeMember("m_domainTable", BindingFlags.NonPublic | BindingFlags.GetField |
BindingFlags.Instance, null, cookieJar, new object[] { });
foreach (var key in table.Keys)
{
foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"http://{key}")))
cookie.Expired = true;
foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"https://{key}")))
cookie.Expired = true;
}
try
{
foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"http://{key}")))
cookie.Expired = true;
foreach (Cookie cookie in cookieJar.GetCookies(new Uri($"https://{key}")))
cookie.Expired = true;
}
catch (Exception)
{
logger.Warn("Unable to delete the cookies of domain: " + key);
}
}

}
Expand Down

0 comments on commit 77bd826

Please sign in to comment.