Skip to content

PR: Sub Issue 1 - Security hardening (SSL fix, HTTP auth, HttpClient pooling)#313

Merged
JusterZhu merged 1 commit into
masterfrom
feature/security-hardening
May 23, 2026
Merged

PR: Sub Issue 1 - Security hardening (SSL fix, HTTP auth, HttpClient pooling)#313
JusterZhu merged 1 commit into
masterfrom
feature/security-hardening

Conversation

@JusterZhu
Copy link
Copy Markdown
Collaborator

Summary

Closes #308

Changes (on unified GeneralUpdate.Core)

  • Fix SSL bypass: Removed \CheckValidationResult()\ returning \ rue. Replaced with \StrictSslValidationPolicy\
  • \ISslValidationPolicy\ interface: Pluggable cert validation
  • \IHttpAuthProvider\ abstraction: 4 built-in implementations (Bearer/API-Key/HMAC/NoOp) + factory
  • HttpClient pooling: Static singleton shared handler — eliminates port exhaustion
  • Retry logic: Exponential backoff (3 attempts) for transient failures

Files

File Change
\Security/ISslValidationPolicy.cs\ New — SSL validation interface
\Security/IHttpAuthProvider.cs\ New — Auth provider + 4 implementations
\Network/VersionService.cs\ Refactored — SSL fix, static HttpClient, auth, retry

Build

✅ 0 errors

…ling

- Remove CheckValidationResult() returning always true
- Add StrictSslValidationPolicy (default: only accept valid certs)
- Add ISslValidationPolicy interface for pluggable cert validation
- Add IHttpAuthProvider with 4 implementations:
  BearerTokenAuthProvider, ApiKeyAuthProvider, HmacAuthProvider, NoOpAuthProvider
- Add HttpAuthProviderFactory for auto-selection
- Replace per-request new HttpClient() with static singleton
- Add exponential-backoff retry (3 attempts, 1s/2s/4s)
- Preserve backward-compatible static API surface

Closes #308
Copilot AI review requested due to automatic review settings May 23, 2026 23:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to harden GeneralUpdate.Core network security by removing the SSL certificate validation bypass, introducing pluggable SSL validation and HTTP auth abstractions, and reworking VersionService to reuse a shared HttpClient with retry logic.

Changes:

  • Added ISslValidationPolicy and a default strict implementation (StrictSslValidationPolicy) to avoid accepting invalid TLS certificates.
  • Added IHttpAuthProvider plus built-in implementations (NoOp/Bearer/API-Key/HMAC) and a factory to apply request authentication.
  • Refactored Network/VersionService to use a shared HttpClient, pluggable TLS validation, pluggable auth, and exponential-backoff retries.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/c#/GeneralUpdate.Core/Security/ISslValidationPolicy.cs Introduces a pluggable certificate validation interface and a strict default policy.
src/c#/GeneralUpdate.Core/Security/IHttpAuthProvider.cs Adds a request-auth abstraction with multiple provider implementations and a factory.
src/c#/GeneralUpdate.Core/Network/VersionService.cs Reworks version/report POSTs to use shared HttpClient + SSL policy + auth provider + retries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +71 to +75
private async Task<VersionRespDTO> ValidateAsync(string url, string v, int at, int pf, string pid,
CancellationToken t = default)
{
var p = new Dictionary<string, object> { ["Version"] = v, ["AppType"] = at, ["Platform"] = pf, ["ProductId"] = pid };
return await PostAsync<VersionRespDTO>(url, p, VersionRespJsonContext.Default.VersionRespDTO, t);
Comment on lines +57 to 63
public static Task<VersionRespDTO> Validate(string url, string version,
int appType, string appKey, int platform, string productId,
string scheme = null, string token = null)
{
var parameters = new Dictionary<string, object>
{
{ "Version", version },
{ "AppType", appType },
{ "AppKey", appKey },
{ "Platform", platform },
{ "ProductId", productId }
};
return await PostTaskAsync<VersionRespDTO>(httpUrl, parameters, VersionRespJsonContext.Default.VersionRespDTO, scheme, token);
var a = HttpAuthProviderFactory.Create(scheme, token, appKey);
return new VersionService(a).ValidateAsync(url, version, appType, platform, productId);
}
Comment on lines +109 to +114
private static bool IsRetryable(Exception ex)
{
if (ex is OperationCanceledException) return false;
if (ex is TaskCanceledException or TimeoutException or System.IO.IOException) return true;
if (ex is HttpRequestException h && (h.Message ?? "").Contains("timeout", StringComparison.OrdinalIgnoreCase)) return true;
return false;
Comment on lines +103 to +105
var r = await _sharedClient.SendAsync(req, cts.Token).ConfigureAwait(false);
r.EnsureSuccessStatusCode();
var rj = await r.Content.ReadAsStringAsync().ConfigureAwait(false);
{
var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = SharedCertValidation;
_sharedClient = new HttpClient(handler, disposeHandler: false);
Comment on lines +66 to +67
var h = new HMACSHA256(Encoding.UTF8.GetBytes(key))
.ComputeHash(Encoding.UTF8.GetBytes(data));
@JusterZhu JusterZhu merged commit 361b12c into master May 23, 2026
1 check passed
@JusterZhu JusterZhu deleted the feature/security-hardening branch May 23, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sub Issue 1: Security hardening - SSL bypass, HttpClient pooling, HTTP auth abstraction

2 participants