Restrict bundled runtime providers to the official Git hosts
This commit is contained in:
1 parent
c4a9612612
commit
7ddf8358a3
5 files changed
+45
-6
No files matched your search
@@ -2,7 +2,7 @@ package runtime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -62,10 +62,10 @@ func isWire2Provider(m Manifest) bool {
|
||||
return false
|
||||
}
|
||||
prefix := releasePrefix(m.Commit)
|
||||
u, err := url.Parse(m.UpstreamRepo)
|
||||
official := m.UpstreamRepo == "https://github.com/"+DefaultReleasesRepo ||
|
||||
m.UpstreamRepo == "https://git.lzgzxs.xyz/"+DefaultReleasesRepo
|
||||
return prefix != "" && len(m.FullCommit) == 40 && strings.Trim(m.FullCommit, "0123456789abcdef") == "" &&
|
||||
strings.HasPrefix(m.FullCommit, prefix) && err == nil && u.Scheme == "https" && u.Host != "" &&
|
||||
u.User == nil && u.RawQuery == "" && !u.ForceQuery && u.Fragment == "" && u.Path == "/"+DefaultReleasesRepo
|
||||
strings.HasPrefix(m.FullCommit, prefix) && official
|
||||
}
|
||||
|
||||
func stockWire2(r Installed) bool {
|
||||
@@ -79,6 +79,15 @@ func (v wire2Proofs) readBundledManifest(dir string, outer Manifest) (Manifest,
|
||||
if !isWire2Provider(outer) || expected == "" || !strings.EqualFold(expected, v.manifestSHA) {
|
||||
return empty, fmt.Errorf("runtime %s has an unrecognized wire-2 bundle declaration", outer.Commit)
|
||||
}
|
||||
for _, part := range []string{".", "compat", "compat/wire2", wire2ManifestPath} {
|
||||
info, err := os.Lstat(filepath.Join(dir, filepath.FromSlash(part)))
|
||||
if err != nil {
|
||||
return empty, err
|
||||
}
|
||||
if wire2Redirect(info) || (part == wire2ManifestPath && !info.Mode().IsRegular()) || (part != wire2ManifestPath && !info.IsDir()) {
|
||||
return empty, fmt.Errorf("invalid wire-2 package path %s", part)
|
||||
}
|
||||
}
|
||||
real, err := filepath.EvalSymlinks(dir)
|
||||
if err != nil {
|
||||
return empty, err
|
||||
|
||||
@@ -57,6 +57,21 @@ func TestBundledWire2SelectsAnEntireVerifiedRuntime(t *testing.T) {
|
||||
if err := pins.verifyPackage(parent.Dir, parent.Manifest); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Run("third-party host using the official repository path", func(t *testing.T) {
|
||||
impostor := parent
|
||||
impostor.Manifest.UpstreamRepo = "https://example.test/reims-go/reims-vgpu"
|
||||
rows := pins.addRuntimes(&cfg, []Installed{impostor, stock})
|
||||
if wire2Provider(rows, "") != nil || len(rows) != 2 {
|
||||
t.Fatal("untrusted source supplied a stock compatibility mode")
|
||||
}
|
||||
if err := pins.verifyPackage(impostor.Dir, impostor.Manifest); err == nil {
|
||||
t.Fatal("untrusted source accepted at install")
|
||||
}
|
||||
impostor.Manifest.UpstreamRepo = "https://git.lzgzxs.xyz/reims-go/reims-vgpu"
|
||||
if err := pins.verifyPackage(impostor.Dir, impostor.Manifest); err != nil {
|
||||
t.Fatalf("official Gitea origin: %v", err)
|
||||
}
|
||||
})
|
||||
t.Run("previous wire-2 translator", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
old := child
|
||||
|
||||
@@ -5,3 +5,5 @@ package runtime
|
||||
import "os"
|
||||
|
||||
func wire2ChangeTime(*os.File) int64 { return 0 }
|
||||
|
||||
func wire2Redirect(info os.FileInfo) bool { return info.Mode()&os.ModeSymlink != 0 }
|
||||
@@ -2,11 +2,17 @@ package runtime
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func wire2Redirect(info os.FileInfo) bool {
|
||||
data, ok := info.Sys().(*syscall.Win32FileAttributeData)
|
||||
return !ok || data.FileAttributes&windows.FILE_ATTRIBUTE_REPARSE_POINT != 0
|
||||
}
|
||||
|
||||
func wire2ChangeTime(f *os.File) int64 {
|
||||
// FILE_BASIC_INFO includes the NTFS change time, which os.FileInfo does
|
||||
// not expose. Zero indicates that the filesystem cannot supply it.
|
||||
|
||||
@@ -37,7 +37,7 @@ func verifyWire2Tree(dir, want string, strict bool) error {
|
||||
state.files = nil
|
||||
return err
|
||||
}
|
||||
if !rootInfo.IsDir() {
|
||||
if !rootInfo.IsDir() || wire2Redirect(rootInfo) {
|
||||
return fmt.Errorf("invalid wire-2 runtime directory %s", dir)
|
||||
}
|
||||
root, err := os.OpenRoot(dir)
|
||||
@@ -52,6 +52,13 @@ func verifyWire2Tree(dir, want string, strict bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
node, err := e.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if wire2Redirect(node) {
|
||||
return fmt.Errorf("unexpected link or reparse point at %s", rel)
|
||||
}
|
||||
if e.IsDir() {
|
||||
return nil
|
||||
}
|
||||
@@ -67,7 +74,7 @@ func verifyWire2Tree(dir, want string, strict bool) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.Mode().IsRegular() {
|
||||
if !info.Mode().IsRegular() || wire2Redirect(info) {
|
||||
return fmt.Errorf("unexpected file type at %s", rel)
|
||||
}
|
||||
now := wire2FileProof{info: info, changed: wire2ChangeTime(f)}
|
||||
|
||||
Reference in new issue
Block a user