Skip to content

Use shared integrity verification - #260

Merged
andrew merged 2 commits into
mainfrom
integrity-migration
Aug 17, 2026
Merged

Use shared integrity verification#260
andrew merged 2 commits into
mainfrom
integrity-migration

Conversation

@andrew

@andrew andrew commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Use github.com/git-pkgs/integrity for cached artifact verification. Parse expected metadata before serving, calculate the required algorithms in one pass, keep content hash and native SRI reporting separate, and discard cache records with malformed integrity values.

Copilot AI left a comment

Copy link
Copy Markdown

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 migrates cached artifact integrity verification to the shared github.com/git-pkgs/integrity library, validating expected hash/SRI metadata up-front and using a single streaming pass to compute required digests before serving cached artifacts.

Changes:

  • Replaced custom SRI parsing + hashing with integrity.Reader and a unified integrityChecks wrapper.
  • Added early rejection/eviction of cache records with malformed content_hash or integrity metadata.
  • Updated handler/database tests and fixtures to use real SHA-256 hex hashes and valid SRI strings; added the new module dependency.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/handler/integrity.go Introduces integrityChecks and shared streaming verification via github.com/git-pkgs/integrity.
internal/handler/integrity_test.go Updates tests to exercise new parsing/verification behaviors and mismatch messaging.
internal/handler/handler.go Rejects unusable cache records before serving; wraps cached reads with shared integrity verification.
internal/handler/handler_test.go Adjusts cache-hit expectations and adds coverage for rejecting malformed integrity metadata.
internal/handler/download_test.go Updates seeded cached artifacts to use SHA-256 hex content hashes.
internal/handler/container_test.go Updates ETag expectations to match SHA-256 hex hashes.
internal/database/database_test.go Replaces placeholder hashes/integrity strings with realistic values in CRUD tests.
go.mod Adds github.com/git-pkgs/integrity v0.1.0.
go.sum Adds checksums for github.com/git-pkgs/integrity v0.1.0.
Suppressed comments (2)

internal/handler/handler.go:264

  • rejectUnusableCacheRecord records an integrity failure metric using artifact.Ecosystem without normalization. For consistency with other metrics labeling (e.g. recordCacheHit), normalize the ecosystem before emitting the metric to avoid label drift.
func (p *Proxy) rejectUnusableCacheRecord(artifact *database.CachedArtifact, versionPURL, filename string, cause error) {
	p.Logger.Warn("cached artifact has unusable integrity metadata",
		"purl", versionPURL, "filename", filename,
		"path", artifact.StoragePath, "error", cause)
	metrics.RecordIntegrityFailure(artifact.Ecosystem)
	if err := p.DB.ClearArtifactCache(versionPURL, filename); err != nil {
		p.Logger.Warn("failed to clear unusable artifact from cache", "error", err)
	}

internal/handler/handler.go:219

  • metrics.RecordIntegrityFailure is labeled with artifact.Ecosystem, which may not be normalized (unlike RecordCacheHit, which uses purl.NormalizeEcosystem). This can split integrity-failure metrics across multiple label variants for the same ecosystem.

This issue also appears on line 257 of the same file.

		func(reason string) {
			p.Logger.Error("cached artifact failed integrity check",
				"purl", versionPURL, "filename", filename,
				"path", artifact.StoragePath, "reason", reason)
			metrics.RecordIntegrityFailure(artifact.Ecosystem)
			if err := p.DB.ClearArtifactCache(versionPURL, filename); err != nil {

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/handler/integrity_test.go
@andrew
andrew force-pushed the integrity-migration branch from 94105f8 to 83f6538 Compare August 17, 2026 08:13
@andrew
andrew merged commit 1a814c7 into main Aug 17, 2026
8 checks passed
@andrew
andrew deleted the integrity-migration branch August 17, 2026 08:20
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