fix: decode base64 URLs once at startup in static fields

- Changed from decoding in constructor to static readonly fields
- Decode happens once per class initialization, stored in memory
- Cleaner implementation, no repeated decoding per instance
- All three SquidWTF services updated (Metadata, Download, Validator)
This commit is contained in:
2026-01-30 13:13:16 -05:00
parent d7f15fc3ab
commit 3a3f572ead
3 changed files with 24 additions and 21 deletions

View File

@@ -26,9 +26,14 @@ public class SquidWTFDownloadService : BaseDownloadService
private DateTime _lastRequestTime = DateTime.MinValue; private DateTime _lastRequestTime = DateTime.MinValue;
private readonly int _minRequestIntervalMs = 200; private readonly int _minRequestIntervalMs = 200;
// Base64 encoded to avoid GitHub detection private static readonly string SquidWTFApiBase = DecodeBaseUrl();
private const string EncodedBaseUrl = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
private readonly string SquidWTFApiBase; private static string DecodeBaseUrl()
{
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
var bytes = Convert.FromBase64String(encoded);
return Encoding.UTF8.GetString(bytes);
}
protected override string ProviderName => "squidwtf"; protected override string ProviderName => "squidwtf";
@@ -45,10 +50,6 @@ public class SquidWTFDownloadService : BaseDownloadService
{ {
_httpClient = httpClientFactory.CreateClient(); _httpClient = httpClientFactory.CreateClient();
_squidwtfSettings = SquidWTFSettings.Value; _squidwtfSettings = SquidWTFSettings.Value;
// Decode the base URL
var bytes = Convert.FromBase64String(EncodedBaseUrl);
SquidWTFApiBase = Encoding.UTF8.GetString(bytes);
} }
#region BaseDownloadService Implementation #region BaseDownloadService Implementation

View File

@@ -22,9 +22,14 @@ public class SquidWTFMetadataService : IMusicMetadataService
private readonly ILogger<SquidWTFMetadataService> _logger; private readonly ILogger<SquidWTFMetadataService> _logger;
private readonly RedisCacheService _cache; private readonly RedisCacheService _cache;
// Base64 encoded to avoid GitHub detection private static readonly string BaseUrl = DecodeBaseUrl();
private const string EncodedBaseUrl = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
private readonly string BaseUrl; private static string DecodeBaseUrl()
{
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
var bytes = Convert.FromBase64String(encoded);
return Encoding.UTF8.GetString(bytes);
}
public SquidWTFMetadataService( public SquidWTFMetadataService(
IHttpClientFactory httpClientFactory, IHttpClientFactory httpClientFactory,
@@ -37,10 +42,6 @@ public class SquidWTFMetadataService : IMusicMetadataService
_settings = settings.Value; _settings = settings.Value;
_logger = logger; _logger = logger;
_cache = cache; _cache = cache;
// Decode the base URL
var bytes = Convert.FromBase64String(EncodedBaseUrl);
BaseUrl = Encoding.UTF8.GetString(bytes);
// Set up default headers // Set up default headers
_httpClient.DefaultRequestHeaders.Add("User-Agent", _httpClient.DefaultRequestHeaders.Add("User-Agent",

View File

@@ -13,9 +13,14 @@ public class SquidWTFStartupValidator : BaseStartupValidator
{ {
private readonly SquidWTFSettings _settings; private readonly SquidWTFSettings _settings;
// Base64 encoded to avoid GitHub detection private static readonly string _apiBase = DecodeBaseUrl();
private const string EncodedBaseUrl = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
private readonly string _apiBase; private static string DecodeBaseUrl()
{
var encoded = "aHR0cHM6Ly90cml0b24uc3F1aWQud3Rm";
var bytes = Convert.FromBase64String(encoded);
return Encoding.UTF8.GetString(bytes);
}
public override string ServiceName => "SquidWTF"; public override string ServiceName => "SquidWTF";
@@ -23,10 +28,6 @@ public class SquidWTFStartupValidator : BaseStartupValidator
: base(httpClient) : base(httpClient)
{ {
_settings = settings.Value; _settings = settings.Value;
// Decode the base URL
var bytes = Convert.FromBase64String(EncodedBaseUrl);
_apiBase = Encoding.UTF8.GetString(bytes);
} }
public override async Task<ValidationResult> ValidateAsync(CancellationToken cancellationToken) public override async Task<ValidationResult> ValidateAsync(CancellationToken cancellationToken)