Skip to content

GeneralUpdate.Extension 11.0: production hardening, auto-update pipeline, package signatures, ALC loader - #565

Merged
JusterZhu merged 6 commits into
masterfrom
feat/extension-11-production-hardening
Dec 5, 2026
Merged

JusterZhu merged 6 commits into
masterfrom
feat/extension-11-production-hardening

Conversation

@JusterZhu

Copy link
Copy Markdown
Collaborator

Summary

Brings GeneralUpdate.Extension to production standard: fixes four correctness bugs found in review, hardens security and concurrency, completes the update feature set (update checks, auto-update scheduler, package signatures, rollback, health scan), ships a new AssemblyLoadContext loader package, and raises the test suite from 367 to 483 tests including real-HTTP end-to-end and .NET Framework 4.8 runtime smoke coverage.

Version: 10.5.0 → 11.0.0 (interface additions are breaking for custom implementers; migration notes in the docs).

Safety fixes

  • Download resume: only resumes on 206 PartialContent; a plain 200 restarts the file (previously appended a full body onto a partial file → corrupted packages); 416 is verified against the Content-Range total before counting as "already downloaded"
  • Circular-dependency guard in the recursive dependency installer (A→B→A no longer overflows the stack)
  • Local installs now register in the catalog (manifest written; previously vanished after restart)
  • Server UploadTime preserved; package manifest no longer shadows server metadata

Hardening

  • Server-controlled Name/Version/Format sanitized before filesystem use (path-traversal-proof)
  • Cross-process catalog file lock (.catalog.lock, self-healing on process crash)
  • Zip Slip entries now fail the whole install (previously partially installed); entry-count/uncompressed-size limits guard against zip bombs
  • Corrupt manifests skip with a warning instead of failing the entire catalog load
  • Download retries with exponential backoff, resume-aware (DownloadRetryAttempts, default 2)
  • Thread-safety fixes (queue processing gate, concurrent auto-update settings)
  • GeneralTracer no longer clears host Trace.Listeners; pluggable ITraceSink/ILoggerFactory

New features

  • CheckForUpdatesAsync / CheckAndApplyUpdatesAsync + ExtensionUpdatesChecked event
  • Built-in auto-update scheduler (interval, global/per-extension flags, persisted settings)
  • RSA-SHA256 package signature verification (SigningPublicKey + Signature metadata)
  • Dependency version constraints: id@^range syntax (VersionRange/DependencyRef)
  • InstallFromLocalAsync: offline install with explicit SHA256 verification
  • RollbackToAsync with retained previous-version backups; optional SideBySideVersions layout
  • ScanAsync health scan with repair (freshness window protects in-flight downloads)
  • QueryAllExtensionsAsync: auto-paging IAsyncEnumerable iterator
  • Phase field on update events (download/install/uninstall/activation/rollback/check)
  • CancellationToken across the whole IExtensionHost surface; CancelDownload API
  • GET-with-body query auto-falls back to POST (AutoFallbackToPost)
  • HttpClient options: timeout, explicit proxy, UseSystemProxy, user agent
  • New package GeneralUpdate.Extension.Loader (net8.0): collectible AssemblyLoadContext loader with IExtensionEntryPoint convention

Packaging & tooling

  • Examples/ moved out of the NuGet package into samples/GeneralUpdate.Extension.Samples
  • New read-only ServerSmokeTool (samples/GeneralUpdate.Extension.SmokeTool) for verifying a real server's contract before deployment
  • dotnet pack verified: both packages build with symbols, README, icons

Tests

367 → 483, all green:

  • Feature suite (update pipeline, rollback, scan, scheduler with real timers, signature, version ranges)
  • Real-HTTP end-to-end over sockets (full lifecycle incl. resume, hash+signature, rollback, scan, uninstall)
  • Production-hardening tests (path-traversal vectors, cross-process lock, retry behavior)
  • ExtensionNet48SmokeTest: runs the netstandard2.0 library on the .NET Framework 4.8 runtime (IO/compression/RSA/HTTP/resume)

Docs

  • docs/extension-system.md: full system guide (lifecycle, security model, dependency constraints, scheduler, rollback, loader, server API contract) + production deployment checklist + 10.x→11.0 migration notes

Safety fixes:
- Resume only on 206 PartialContent; a plain 200 restarts the file; 416 is
  verified against the server-declared total size before counting as complete
- Circular-dependency guard in the recursive dependency installer (no stack overflow)
- Local installs register in the catalog (manifest written, survives restarts)
- Server UploadTime preserved; package manifest no longer shadows server metadata

Hardening:
- Sanitize server-controlled Name/Version/Format before filesystem use
- Cross-process catalog file lock (.catalog.lock, self-healing on crash)
- Zip extraction: traversal entries fail the whole install; entry-count and
  uncompressed-size limits guard against zip bombs
- Corrupt manifests are skipped with a warning instead of failing the whole load
- Download retries with exponential backoff, resume-aware (DownloadRetryAttempts)
- Thread safety: concurrent auto-update settings, queue processing gate, volatile flags
- GeneralTracer no longer clears host Trace listeners; pluggable ITraceSink/ILogger

Features:
- CheckForUpdatesAsync / CheckAndApplyUpdatesAsync + ExtensionUpdatesChecked event
- Built-in auto-update scheduler (interval, global/per-extension flags, persisted)
- RSA-SHA256 package signature verification (SigningPublicKey + Signature metadata)
- Dependency version constraints: id@^range syntax via VersionRange/DependencyRef
- InstallFromLocalAsync: offline install with explicit SHA256 verification
- RollbackToAsync with retained previous-version backups; SideBySideVersions layout
- ScanAsync health scan with repair (freshness window protects in-flight downloads)
- QueryAllExtensionsAsync: auto-paging IAsyncEnumerable iterator
- Phase field on update events; AlreadyUpToDate/DowngradeBlocked statuses
- CancellationToken across the IExtensionHost surface; CancelDownload API
- GET-with-body query auto-falls back to POST (AutoFallbackToPost)
- HttpClient options: timeout, explicit proxy, UseSystemProxy, user agent
- GeneralUpdate.Extension.Loader (net8.0): collectible AssemblyLoadContext loader

Packaging and tests:
- Version 11.0.0; Examples moved out of the NuGet package into samples projects
- Read-only ServerSmokeTool sample for production-server contract verification
- 483 tests: feature suite, real-HTTP end-to-end, production hardening,
  and a .NET Framework 4.8 runtime smoke project
- docs/extension-system.md: full system guide and production deployment checklist
Copilot AI balanced review requested due to automatic review settings December 4, 2026 10:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical issues allow catalog path traversal and parent-directory deletion, undermine cross-process locking, and can leave downloads hanging during shutdown.

25 open issues

And 5 more that still need to be addressed.

What changed in this PR

Upgrades GeneralUpdate.Extension to 11.0 with production hardening, expanded update APIs, and a separate collectible assembly loader.

Changes:

  • Adds update scheduling, signature verification, dependency ranges, rollback, and health-scan support.
  • Hardens downloads, catalog persistence, concurrency, and tracing.
  • Expands tests, separates samples, and adds deployment documentation and a server smoke tool.
File Description
tests/​ExtensionTest/​Utilities/​VersionRangeTests.cs Tests dependency parsing and range semantics.
tests/​ExtensionTest/​Utilities/​PackageSignatureVerifierTests.cs Tests signature verification and rejection cases.
tests/​ExtensionTest/​Tracer/​GeneralTracerSinkTests.cs Tests custom tracing sinks.
tests/​ExtensionTest/​TestExtensionSample/​TestExtensionSample.csproj Adds the loader test fixture project.
tests/​ExtensionTest/​TestExtensionSample/​TestEntryPoint.cs Implements a sample extension entry point.
tests/​ExtensionTest/​Loader/​AssemblyContextExtensionLoaderTests.cs Tests loading, unloading, and host integration.
tests/​ExtensionTest/​ExtensionTest.csproj References loader and tracing dependencies.
tests/​ExtensionTest/​Core/​ProductionHardeningTests.cs Tests sanitization, locks, retries, and scheduling.
tests/​ExtensionTest/​Core/​ExtensionHostFeatureTests.cs Covers the expanded host lifecycle.
tests/​ExtensionTest/​Communication/​ExtensionHttpClientResumeTests.cs Tests resume handling and query fallback.
tests/​ExtensionTest/​Communication/​ExtensionHostEndToEndTests.cs Adds real-HTTP lifecycle tests.
tests/​ExtensionTest/​Catalog/​ExtensionCatalogTests.cs Checks corrupt-manifest isolation.
tests/​ExtensionNet48SmokeTest/​Net48SmokeTests.cs Adds Framework runtime smoke coverage.
tests/​ExtensionNet48SmokeTest/​ExtensionNet48SmokeTest.csproj Defines the .NET Framework 4.8 test project.
tests/​Directory.Packages.props Adds the logging abstraction dependency version.
src/​GeneralUpdate.slnx Includes loader, samples, and smoke tests.
src/​GeneralUpdate.Extension/​Utilities/​VersionRange.cs Adds dependency-reference and version-range parsing.
src/​GeneralUpdate.Extension/​Utilities/​PackageSignatureVerifier.cs Adds RSA-SHA256 signing and verification.
src/​GeneralUpdate.Extension/​Tracer/​TextTraceListener.cs Explicitly marks disposal-method hiding.
src/​GeneralUpdate.Extension/​Tracer/​GeneralTracer.cs Adds configurable sinks and preserves host listeners.
src/​GeneralUpdate.Extension/​GeneralUpdate.Extension.csproj Updates package metadata and dependencies for 11.0.
src/​GeneralUpdate.Extension/​Download/​IDownloadQueueManager.cs Adds task-removal API.
src/​GeneralUpdate.Extension/​Download/​DownloadQueueManager.cs Adds retries, completion signals, and queue coordination.
src/​GeneralUpdate.Extension/​Core/​RegistryExtensionLoader.cs Adds the default registry-only loader.
src/​GeneralUpdate.Extension/​Core/​IExtensionMetadataMapper.cs Maps package signatures.
src/​GeneralUpdate.Extension/​Core/​IExtensionLoader.cs Defines loading and entry-point contracts.
src/​GeneralUpdate.Extension/​Core/​IExtensionHost.cs Expands lifecycle APIs, cancellation, and events.
src/​GeneralUpdate.Extension/​Core/​ExtensionHostBuilder.cs Registers loader and configurable queue/catalog defaults.
src/​GeneralUpdate.Extension/​Concurrency/​FileLock.cs Adds cross-process file locking.
src/​GeneralUpdate.Extension/​Communication/​ExtensionHttpClient.cs Adds resume safeguards, query fallback, and HTTP options.
src/​GeneralUpdate.Extension/​Common/​Models/​ExtensionUpdateInfo.cs Describes available updates.
src/​GeneralUpdate.Extension/​Common/​Models/​ExtensionScanReport.cs Models health-scan results.
src/​GeneralUpdate.Extension/​Common/​Models/​ExtensionMetadata.cs Adds signatures and persisted update preferences.
src/​GeneralUpdate.Extension/​Common/​Models/​ExtensionHostOptions.cs Adds security, scheduling, storage, and HTTP settings.
src/​GeneralUpdate.Extension/​Common/​Models/​DownloadTask.cs Adds awaitable download completion.
src/​GeneralUpdate.Extension/​Common/​Enums/​ExtensionUpdateStatus.cs Adds up-to-date and downgrade-blocked statuses.
src/​GeneralUpdate.Extension/​Common/​Enums/​ExtensionUpdatePhase.cs Identifies lifecycle event phases.
src/​GeneralUpdate.Extension/​Common/​DTOs/​HttpResponseDTO.cs Exposes transport status without serializing it.
src/​GeneralUpdate.Extension/​Common/​DTOs/​ExtensionDTO.cs Adds server-provided package signatures.
src/​GeneralUpdate.Extension/​Catalog/​ExtensionCatalog.cs Adds locking, version selection, and resilient loading.
src/​GeneralUpdate.Extension.Loader/​README.md Documents loader setup and behavior.
src/​GeneralUpdate.Extension.Loader/​GeneralUpdate.Extension.Loader.csproj Defines the separate net8.0 loader package.
src/​GeneralUpdate.Extension.Loader/​AssemblyContextExtensionLoader.cs Implements collectible assembly loading.
samples/​GeneralUpdate.Extension.SmokeTool/​Program.cs Adds server query and download probes.
samples/​GeneralUpdate.Extension.SmokeTool/​GeneralUpdate.Extension.SmokeTool.csproj Defines the smoke-tool executable.
samples/​GeneralUpdate.Extension.Samples/​VersionCompatibilityExample.cs Moves compatibility example into the samples namespace.
samples/​GeneralUpdate.Extension.Samples/​PlatformMatcherExample.cs Moves platform example into the samples namespace.
samples/​GeneralUpdate.Extension.Samples/​InstallExtensionExample.cs Moves installation example into the samples namespace.
samples/​GeneralUpdate.Extension.Samples/​GeneralUpdate.Extension.Samples.csproj Separates examples from the library package.
samples/​GeneralUpdate.Extension.Samples/​ExtensionExample.cs Moves lifecycle example into the samples namespace.
samples/​GeneralUpdate.Extension.Samples/​ExtensionCatalogExample.cs Moves catalog example into the samples namespace.
samples/​GeneralUpdate.Extension.Samples/​DownloadQueueExample.cs Moves queue example into the samples namespace.
samples/​GeneralUpdate.Extension.Samples/​DependencyResolverExample.cs Moves dependency example into the samples namespace.
docs/​extension-system.md Adds system, deployment, and migration guidance.

Review effort: Balanced

…resume, tracer ownership

Catalog
- A server-supplied name or version goes through the same sanitizer as the
  installation (SafeNames.DirectoryName), so a Name/Version of ".." can no
  longer point the manifest write - or a later RemoveInstalledExtension -
  outside the catalog directory.
- The .active pointer is sanitized on read like any directory name, so a
  hostile pointer cannot lead the manifest read outside the extension.
- The side-by-side load resolves the pointer/highest-version manifest first
  and uses the legacy root manifest only as a fallback, so a stale
  {name}/manifest.json no longer outranks the version that was selected.
- Saving one extension writes only that extension's manifest and pointer under
  the lock, instead of every entry of the in-memory snapshot: a second host
  loaded at v1 could push the first host's v2 pointer back to v1 by changing
  settings for an unrelated extension.
- FileLock keeps the lock file and only releases its handle: mutual exclusion
  is tied to the open handle, and deleting the pathname afterwards would let a
  third process lock a new file under the same name while a second process
  still holds the old one.

Download queue
- Tracking a task is an atomic add-or-replace of a finished task; concurrent
  enqueues for one extension cannot both get in.
- Cleanup removes a task only while it is still the one tracked for its ID, so
  a finished task can no longer remove its successor.
- A dequeued task is completed as failed when disposal (or anything else)
  keeps its download from starting; the loop holds the disposal token from
  construction, so reading it after Dispose cannot throw.

Loader (net8.0+)
- The extension directory is made absolute before assembly discovery, so the
  documented "./extensions" configuration loads instead of throwing in
  LoadFromAssemblyPath.
- Load/unload is serialized per loader; concurrent activations of one ID can
  no longer build two contexts and drop one from the record.
- A missing dependency or a throwing entry-point constructor fails the load
  (the context is unloaded, the record is not kept) instead of reporting a
  load without an entry point.
- The host's contract assembly is shared before extension-local resolution:
  an extension that ships its own GeneralUpdate.Extension.dll is still
  recognized as implementing the host's IExtensionEntryPoint.

HTTP client
- The POST fallback also runs when GET fails before a response exists
  (transport/protocol rejection), so POST-only transports work; a failing
  fallback reports both failures.
- A 206 whose Content-Range does not start at the local file's end is not
  appended; the download restarts instead of corrupting the file.

Builder
- Proxy, UseSystemProxy, HttpTimeout and UserAgent are forwarded to the
  default ExtensionHttpClient registration; they were silently ignored
  through the recommended builder.

Tracer
- EnableFileLogging=false detaches and disposes an existing log listener, and
  the initial file setup is deferred to the first trace message, so an opt-out
  never requires a writable Logs directory.
- EnableConsoleListener=false removes the owned console listener and restores
  it when re-enabled; repeated ResetToDefaultListeners calls no longer stack
  duplicate listeners.
- SetTracingEnabled only switches the filters of listeners this library owns,
  leaving host listeners untouched.

Smoke tool
- The main client uses POST for the query check (the GET probe stays separate).
- The download probe verifies the actual 206 + Content-Range start instead of
  declaring resume working when a server ignores the Range.

Range/version-range semantics
- A comparator list that names an empty interval (">=2.0.0 1.0.0") parses to
  an empty range - nothing satisfies it - instead of failing to parse, so
  dependency resolution reports an unsatisfiable constraint rather than a
  syntax error; and comparators now always intersect (exact, caret, tilde
  included), closing the widening that made ">=2.0.0 1.0.0" accept 1.0.0.

Framework smoke
- The net48 HTTP test asserts the query transport returned the server item
  (registering an installed extension and expecting its update entry), instead
  of passing on an empty error response.

Regressions: ExtensionCatalogPathAndPointerTests, GeneralTracerListenerTests,
AssemblyContextLoaderDeploymentTests, ExtensionHttpClientResumeTests
(broken-range restart, GET-transport-failure fallback, synchronous progress),
VersionRangeTests (intersection and order-reversal cases), Net48SmokeTests.
…e layouts

Path.GetRelativePath returns the absolute target when the working directory
and the temp directory are on different drives - the layout of the Windows CI
runner (repository on D:, temp on C:) - so asserting non-rootedness failed
there instead of exercising the loader. The assertion now guards the case.
@JusterZhu
JusterZhu merged commit e067913 into master Dec 5, 2026
6 checks passed
@JusterZhu
JusterZhu deleted the feat/extension-11-production-hardening branch December 5, 2026 12:27
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.

2 participants