fixed issues from opencode agent

This commit is contained in:
2026-05-13 01:08:19 +02:00
parent 994570ca74
commit dea58b85b8
6 changed files with 29 additions and 14 deletions
+5 -4
View File
@@ -27,7 +27,7 @@ type Registry struct {
// New creates a Registry rooted at ociRoot, creating the directory tree if needed.
func New(ociRoot string) (*Registry, error) {
for _, sub := range []string{"blobs/sha256", "uploads"} {
if err := os.MkdirAll(filepath.Join(ociRoot, sub), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(ociRoot, sub), 0700); err != nil {
return nil, fmt.Errorf("oci: init storage %s: %w", sub, err)
}
}
@@ -174,7 +174,7 @@ func (r *Registry) FinishUpload(uploadID, clientDigest string) (digest string, s
// new total offset.
func (r *Registry) AppendUpload(uploadID string, src io.Reader) (newOffset int64, err error) {
path := r.UploadPath(uploadID)
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
return 0, fmt.Errorf("oci: open upload for append: %w", err)
}
@@ -291,9 +291,10 @@ func digestHex(digest string) (string, error) {
return h, nil
}
// sanitiseID strips any path separators from an upload ID.
// sanitiseID returns only the last path component of an upload ID,
// preventing any path traversal regardless of encoding.
func sanitiseID(id string) string {
return strings.NewReplacer("/", "", "\\", "", "..", "").Replace(id)
return filepath.Base(id)
}
// ParseOCIPath extracts the image name and the operation kind from a path