diff --git a/src/Jackett.Common/Indexers/BaseIndexer.cs b/src/Jackett.Common/Indexers/BaseIndexer.cs index 1745b91ba..c587bcfc6 100644 --- a/src/Jackett.Common/Indexers/BaseIndexer.cs +++ b/src/Jackett.Common/Indexers/BaseIndexer.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using AutoMapper; using Jackett.Common.Models; @@ -349,6 +350,9 @@ namespace Jackett.Common.Indexers public abstract class BaseWebIndexer : BaseIndexer, IWebIndexer { + // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie + private readonly Regex _cookieRegex = new Regex(@"([^\(\)<>@,;:\\""/\[\]\?=\{\}\s]+)=([^,;\\""\s]+)"); + protected BaseWebIndexer(string name, string link, string description, IIndexerConfigurationService configService, WebClient client, Logger logger, ConfigurationData configData, IProtectionService p, TorznabCapabilities caps = null, string downloadBase = null) : base(name, link, description, configService, logger, configData, p) { @@ -605,17 +609,16 @@ namespace Jackett.Common.Indexers private string ResolveCookies(string incomingCookies = "") { - var redirRequestCookies = (CookieHeader != null && CookieHeader != "" ? CookieHeader + " " : "") + incomingCookies; - var expression = new System.Text.RegularExpressions.Regex(@"([^\\,;\s]+)=([^=\\,;\s]*)"); - var cookieDIctionary = new Dictionary(); - var matches = expression.Match(redirRequestCookies); + var redirRequestCookies = string.IsNullOrWhiteSpace(CookieHeader) ? incomingCookies : CookieHeader + " " + incomingCookies; + var cookieDictionary = new Dictionary(); + var matches = _cookieRegex.Match(redirRequestCookies); while (matches.Success) { if (matches.Groups.Count > 2) - cookieDIctionary[matches.Groups[1].Value] = matches.Groups[2].Value; + cookieDictionary[matches.Groups[1].Value] = matches.Groups[2].Value; matches = matches.NextMatch(); } - return string.Join("; ", cookieDIctionary + return string.Join("; ", cookieDictionary .Where(kv => kv.Key != "cf_use_ob" && kv.Key != "cf_ob_info") // These cookies are causing BadGateway errors, so we drop them, see issue #2306 .Select(kv => kv.Key.ToString() + "=" + kv.Value.ToString()).ToArray()); }