Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
changes:
name: Detect changes
Expand Down
4 changes: 4 additions & 0 deletions internal/adapters/out/filesystem/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"time"

"github.com/bnema/zerowrap"
Expand Down Expand Up @@ -263,6 +264,9 @@ func (s *ManifestStorage) GetManifestModTime(name, reference string) (time.Time,

func (s *ManifestStorage) getManifestPath(name, reference string) (string, error) {
// Validate name to prevent path traversal (defense in depth)
if strings.Contains(name, "..") || strings.Contains(reference, "..") {
return "", fmt.Errorf("path traversal not allowed")
}
if _, err := validation.ValidatePath(name); err != nil {
return "", fmt.Errorf("invalid repository name: %w", err)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/usecase/logs/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,17 @@ func (s *Service) FollowContainerLogs(ctx context.Context, domain string, initia
return ch, nil
}

// maxTailLines bounds the ring buffer allocated by tailLines.
const maxTailLines = 10000

// tailLines reads the last N lines from a file using a ring buffer.
func tailLines(file *os.File, n int) ([]string, error) {
if n <= 0 {
return []string{}, nil
}
if n > maxTailLines {
n = maxTailLines
}

// Seek to beginning
if _, err := file.Seek(0, io.SeekStart); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/usecase/registry/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ func (s *Service) validateManifestBlobs(name string, data []byte) error {
if descriptor.Digest == "" {
continue
}
if err := validation.ValidateDigest(descriptor.Digest); err != nil {
return fmt.Errorf("%w: %s", domain.ErrManifestBlobUnknown, err)
}
if _, _, err := s.manifestStorage.GetManifest(name, descriptor.Digest); err != nil {
return fmt.Errorf("%w: %s", domain.ErrManifestBlobUnknown, descriptor.Digest)
}
Expand Down
18 changes: 18 additions & 0 deletions internal/usecase/registry/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,24 @@ func TestService_PutManifest_RejectsUnknownChildManifest(t *testing.T) {
require.ErrorIs(t, err, domain.ErrManifestBlobUnknown)
}

func TestService_PutManifest_RejectsMalformedChildDigest(t *testing.T) {
blobStorage := mocks.NewMockBlobStorage(t)
manifestStorage := mocks.NewMockManifestStorage(t)
svc := NewService(blobStorage, manifestStorage, nil)

manifest := &domain.Manifest{
Name: "index",
Reference: "latest",
ContentType: "application/vnd.oci.image.index.v1+json",
Data: []byte(`{"schemaVersion":2,"manifests":[{"digest":"../../tags.json"}]}`),
}

_, err := svc.PutManifest(testContext(), manifest)

require.ErrorIs(t, err, domain.ErrManifestBlobUnknown)
manifestStorage.AssertNotCalled(t, "GetManifest", mock.Anything, mock.Anything)
}

func TestService_PutManifest_SHA512DigestDoesNotPublishEvent(t *testing.T) {
blobStorage := mocks.NewMockBlobStorage(t)
manifestStorage := mocks.NewMockManifestStorage(t)
Expand Down
Loading