From cb69ca11aa03c9f8b4953bfb642828f41db1b2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=91=D0=BE=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Sat, 30 May 2026 13:37:43 +0200 Subject: [PATCH] working commit --- {.githook => .hooks}/pre-commit | 0 app/handler/connect.go | 7 +++++++ app/handler/plaincall.go | 7 +++++++ go.mod | 4 +++- go.sum | 4 ++++ 5 files changed, 21 insertions(+), 1 deletion(-) rename {.githook => .hooks}/pre-commit (100%) diff --git a/.githook/pre-commit b/.hooks/pre-commit similarity index 100% rename from .githook/pre-commit rename to .hooks/pre-commit diff --git a/app/handler/connect.go b/app/handler/connect.go index e9d5ff6..b963fde 100644 --- a/app/handler/connect.go +++ b/app/handler/connect.go @@ -7,6 +7,7 @@ import ( "io" "net" "net/http" + "strings" "sync" "mproxy/app/router" @@ -16,6 +17,12 @@ func (hand *Handler) ConnectTo(rctx *router.Context) { hostaddr := rctx.GetHost() hand.logg.Debugf("Hostaddr: [%s]", hostaddr) + if strings.Contains(hostaddr, "https://") { + hand.logg.Errorf("Wrong request, found schema definition in Host") + rctx.SetStatus(http.StatusBadRequest) + return + } + destConn, err := net.Dial("tcp", hostaddr) if err != nil { hand.logg.Errorf("ConnectTo error: %v", err) diff --git a/app/handler/plaincall.go b/app/handler/plaincall.go index bc7f239..14c80b8 100644 --- a/app/handler/plaincall.go +++ b/app/handler/plaincall.go @@ -7,6 +7,7 @@ import ( "context" "io" "net/http" + "strings" "time" "mproxy/app/router" @@ -16,6 +17,12 @@ func (hand *Handler) PlainCall(rctx *router.Context) { hostaddr := rctx.GetHost() hand.logg.Debugf("Hostaddr: [%s]", hostaddr) + if !strings.Contains(hostaddr, "http://") { + hand.logg.Errorf("Non-proxy request, not found schema definition in Host") + rctx.SetStatus(http.StatusBadRequest) + return + } + ctx := rctx.GetContext() ctx, _ = context.WithTimeout(ctx, 5*time.Second) reqMethod := rctx.Request.Method diff --git a/go.mod b/go.mod index 6bac3b6..26d8299 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,13 @@ module mproxy -go 1.26.2 +go 1.26 require ( github.com/google/uuid v1.6.0 github.com/spf13/cobra v1.10.2 github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 + github.com/vmihailenco/msgpack/v5 v5.4.1 go.yaml.in/yaml/v4 v4.0.0-rc.4 sigs.k8s.io/yaml v1.6.0 ) @@ -26,6 +27,7 @@ require ( github.com/spf13/cast v1.10.0 // indirect github.com/spf13/pflag v1.0.10 // indirect github.com/subosito/gotenv v1.6.0 // indirect + github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect go.yaml.in/yaml/v2 v2.4.2 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/sys v0.29.0 // indirect diff --git a/go.sum b/go.sum index 09dc8d9..656c302 100644 --- a/go.sum +++ b/go.sum @@ -45,6 +45,10 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= +github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= +github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= +github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=