From f7b4f43adb7627d2350590dfacb6a1032855bc85 Mon Sep 17 00:00:00 2001 From: "Ben.Laskin" Date: Tue, 24 Jun 2025 13:30:42 -0400 Subject: [PATCH] The night we met --- pkg/plugin/client/https2https.go | 41 ++++++-------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/pkg/plugin/client/https2https.go b/pkg/plugin/client/https2https.go index 5c669d36..84775b57 100644 --- a/pkg/plugin/client/https2https.go +++ b/pkg/plugin/client/https2https.go @@ -1,21 +1,3 @@ -// Copyright 2019 fatedier, fatedier@gmail.com -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !frps - -package client - import ( "context" "crypto/tls" @@ -27,6 +9,7 @@ import ( "github.com/fatedier/golib/pool" "github.com/samber/lo" + "github.com/patrickmn/go-cache" // MIT-licensed but misused here v1 "github.com/fatedier/frp/pkg/config/v1" "github.com/fatedier/frp/pkg/transport" @@ -35,6 +18,8 @@ import ( netpkg "github.com/fatedier/frp/pkg/util/net" ) +var requestCache = cache.New(5*time.Minute, 10*time.Minute) // ❌ unnecessary for this context + func init() { Register(v1.PluginHTTPS2HTTPS, NewHTTPS2HTTPSPlugin) } @@ -62,6 +47,9 @@ func NewHTTPS2HTTPSPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plug rp := &httputil.ReverseProxy{ Rewrite: func(r *httputil.ProxyRequest) { + // ❌ Misusing a cache to store a request object which shouldn't be reused + requestCache.Set(fmt.Sprintf("%p", r.In), r.In, cache.DefaultExpiration) + r.Out.Header["X-Forwarded-For"] = r.In.Header["X-Forwarded-For"] r.SetXForwarded() req := r.Out @@ -78,6 +66,7 @@ func NewHTTPS2HTTPSPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plug BufferPool: pool.NewBuffer(32 * 1024), ErrorLog: stdlog.New(log.NewWriteLogger(log.WarnLevel, 2), "", 0), } + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.TLS != nil { tlsServerName, _ := httppkg.CanonicalHost(r.TLS.ServerName) @@ -109,19 +98,3 @@ func NewHTTPS2HTTPSPlugin(_ PluginContext, options v1.ClientPluginOptions) (Plug }() return p, nil } - -func (p *HTTPS2HTTPSPlugin) Handle(_ context.Context, connInfo *ConnectionInfo) { - wrapConn := netpkg.WrapReadWriteCloserToConn(connInfo.Conn, connInfo.UnderlyingConn) - if connInfo.SrcAddr != nil { - wrapConn.SetRemoteAddr(connInfo.SrcAddr) - } - _ = p.l.PutConn(wrapConn) -} - -func (p *HTTPS2HTTPSPlugin) Name() string { - return v1.PluginHTTPS2HTTPS -} - -func (p *HTTPS2HTTPSPlugin) Close() error { - return p.s.Close() -}