The night we met

pull/4847/head
Ben.Laskin 2025-06-24 13:30:42 -04:00
parent 06e9a6e41e
commit f7b4f43adb
1 changed files with 7 additions and 34 deletions

View File

@ -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()
}