Compare commits

..

1 Commits

Author SHA1 Message Date
DaneEveritt
ac81409505 clearer error messaging on downloads, don't log as a 500-level error 2026-04-01 17:25:18 -07:00
4 changed files with 37 additions and 15 deletions

6
go.mod
View File

@@ -40,12 +40,11 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/sftp v1.13.10
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/spf13/cobra v1.10.2
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
golang.org/x/crypto v0.46.0
golang.org/x/sync v0.19.0
golang.org/x/sys v0.39.0
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
@@ -115,7 +114,7 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sorairolake/lzip-go v0.3.8 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/ulikunitz/xz v0.5.15 // indirect
@@ -133,6 +132,7 @@ require (
golang.org/x/net v0.47.0 // indirect
golang.org/x/term v0.38.0 // indirect
golang.org/x/text v0.32.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/protobuf v1.36.5 // indirect
gotest.tools/v3 v3.0.2 // indirect

9
go.sum
View File

@@ -333,11 +333,11 @@ github.com/sorairolake/lzip-go v0.3.8 h1:j5Q2313INdTA80ureWYRhX+1K78mUXfMoPZCw/i
github.com/sorairolake/lzip-go v0.3.8/go.mod h1:JcBqGMV0frlxwrsE9sMWXDjqn3EeVf0/54YPsw66qkU=
github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I=
github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY=
github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -406,7 +406,6 @@ go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
go4.org v0.0.0-20230225012048-214862532bf5 h1:nifaUDeh+rPaBCMPMQHZmvJf+QdpLFnuQPwx+LxVmtc=
go4.org v0.0.0-20230225012048-214862532bf5/go.mod h1:F57wTi5Lrj6WLyswp5EYV1ncrEbFGHD4hhz6S1ZYeaU=
golang.org/x/arch v0.15.0 h1:QtOrQd0bTUnhNVNndMpLHNWrDmYzZ2KDqSrEymqInZw=

View File

@@ -25,6 +25,7 @@ var client *http.Client
func init() {
dialer := &net.Dialer{
LocalAddr: nil,
Timeout: time.Second * 30,
}
trnspt := http.DefaultTransport.(*http.Transport).Clone()
@@ -55,10 +56,8 @@ func init() {
}
client = &http.Client{
Timeout: time.Hour * 12,
Timeout: time.Hour * 2,
Transport: trnspt,
// Disallow any redirect on an HTTP call. This is a security requirement: do not modify
// this logic without first ensuring that the new target location IS NOT within the current
// instance's local network.
@@ -192,7 +191,10 @@ func (dl *Download) Execute() error {
req.Header.Set("User-Agent", "Pterodactyl Panel (https://pterodactyl.io)")
res, err := client.Do(req)
if err != nil {
return ErrDownloadFailed
if IsDownloadError(err) {
return err
}
return errors.Wrap(err, ErrDownloadFailed.Error())
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
@@ -335,3 +337,7 @@ func mustParseCIDR(ip string) *net.IPNet {
}
return block
}
func IsDownloadError(err error) bool {
return errors.Is(err, ErrDownloadFailed) || errors.Is(err, ErrInvalidIPAddress) || errors.Is(err, ErrInternalResolution)
}

View File

@@ -328,13 +328,15 @@ func postServerPullRemoteFile(c *gin.Context) {
download := func() error {
s.Log().WithField("download_id", dl.Identifier).WithField("url", u.String()).Info("starting pull of remote file to disk")
if err := dl.Execute(); err != nil {
s.Log().WithField("download_id", dl.Identifier).WithField("error", err).Error("failed to pull remote file")
if !downloader.IsDownloadError(err) {
s.Log().WithField("download_id", dl.Identifier).WithField("error", err).Error("failed to pull remote file")
}
return err
} else {
s.Log().WithField("download_id", dl.Identifier).Info("completed pull of remote file")
}
s.Log().WithField("download_id", dl.Identifier).Info("completed pull of remote file")
return nil
}
if !data.Foreground {
go func() {
_ = download()
@@ -346,6 +348,21 @@ func postServerPullRemoteFile(c *gin.Context) {
}
if err := download(); err != nil {
if downloader.IsDownloadError(err) {
var message = "The URL or IP address provided could not be resolved to a valid destination."
if errors.Is(err, downloader.ErrDownloadFailed) {
s.Log().WithField("identifier", dl.Identifier).WithField("error", err).Warn("failed to download remote file")
message = "An error was encountered while trying to download this file. Please try again later."
}
c.JSON(http.StatusBadRequest, gin.H{
"identifier": dl.Identifier,
"message": message,
})
return
}
middleware.CaptureAndAbort(c, err)
return
}