Skip to content

fix: harden registry parsing (digests, ports, tag pagination) - #88

Open
Abhinesh Jha (Abhineshhh) wants to merge 2 commits into
microsoft:mainfrom
Abhineshhh:fix/registry-stack
Open

fix: harden registry parsing (digests, ports, tag pagination)#88
Abhinesh Jha (Abhineshhh) wants to merge 2 commits into
microsoft:mainfrom
Abhineshhh:fix/registry-stack

Conversation

@Abhineshhh

Copy link
Copy Markdown
Contributor

Description

Consolidated registry fixes that both touch pkg/infrastructure/scanner/registry.go, stacked into one PR for a clean review/merge.

Related Issues

Fixes #74
Fixes #76

Changes

  1. ExtractRegistryAndRepo — strip @digest first; last : after last / is the tag; support host:port / localhost ([Bug]: ExtractRegistryAndRepo mishandles digest-pinned refs and registries with ports #74)
  2. GetTags pagination — follow Registry API Link: rel=next with n=100; httptest multi-page tests ([Bug]: GetTags does not follow Registry API pagination (Link header) #76)

Stack note

This replaces the overlapping single-file PRs #83 and #84 (closed in favor of this consolidated stack).

Checklist

  • go test ./... passes locally
  • Documentation updated (if applicable)
  • Commits are logical and reviewable in order

ExtractRegistryAndRepo previously split on the first :, which mangled
digest suffixes (@sha256:...) and registries with ports (localhost:5000).
Strip digests first and use the last : after the last / as the tag
separator, matching Docker reference parsing.

Fixes microsoft#74
GetTags issued a single tags/list request and ignored the Link
rel=next header, so large repositories could silently drop tags
before filtering and --max-tags selection.

Page with n=100 and follow next links until exhausted; add unit tests
with a multi-page httptest server.

Fixes microsoft#76

@maniSbindra Mani Bindra (maniSbindra) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Abhinesh Jha (@Abhineshhh) detailed comment on registry.go:76

next := fmt.Sprintf("%s/v2/%s/tags/list?n=%d", s.registryURL, repo, tagsPageSize)
var all []string

for next != "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional resilience hardening: this pagination loop has no visited-URL check or page limit, so a buggy registry or proxy returning a self-referencing or cyclic rel=next link could keep it running indefinitely. The HTTP timeout would not prevent this because it applies separately to each request.

Current MCR endpoints appear to return all tags without a Link header, so this is not a demonstrated MCR issue and should not block the PR. Consider adding visited-URL detection or a reasonable maximum page count for compatibility with other registries and future pagination behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants