Confine local file installation paths

This commit is contained in:
2026-08-10 17:59:29 +00:00
parent 59f3fe3d1d
commit 18ddf00d3d
20 changed files with 694 additions and 153 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"strings"
@@ -45,18 +46,35 @@ func (s *LocalStore) Load(ctx context.Context, path string) (*Manifest, error) {
return nil, fmt.Errorf("load manifest: path is required")
}
data, err := os.ReadFile(path)
file, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("load manifest %q: %w", path, err)
}
defer file.Close()
return s.LoadReader(ctx, file)
}
// LoadReader reads and validates a manifest from a caller-owned reader.
func (s *LocalStore) LoadReader(ctx context.Context, source io.Reader) (*Manifest, error) {
if err := checkContext(ctx); err != nil {
return nil, err
}
if source == nil {
return nil, fmt.Errorf("load manifest: source is required")
}
data, err := io.ReadAll(source)
if err != nil {
return nil, fmt.Errorf("read manifest: %w", err)
}
var m Manifest
if err := json.Unmarshal(data, &m); err != nil {
return nil, fmt.Errorf("decode manifest %q: %w", path, err)
return nil, fmt.Errorf("decode manifest: %w", err)
}
if err := validateLoadedManifest(&m); err != nil {
return nil, fmt.Errorf("manifest %q invalid: %w", path, err)
return nil, fmt.Errorf("manifest invalid: %w", err)
}
normalizeManifest(&m)