Skip to content

Commit

Permalink
fix: remove sensitive informations from original endpoint request
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeuoly committed Dec 15, 2024
1 parent 1974c68 commit 53bd801
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/core/plugin_daemon/endpoint_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func InvokeEndpoint(
for resp.Next() {
chunk, err := resp.Read()
if err != nil {
response.WriteError(err)
return
}

Expand Down
15 changes: 13 additions & 2 deletions internal/service/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,20 @@ func Endpoint(
return
}

var buffer bytes.Buffer
// replace with a new reader
req.Body = io.NopCloser(bytes.NewReader(body))
req.ContentLength = int64(len(body))
req.TransferEncoding = nil

// remove ip traces for security
req.Header.Del("X-Forwarded-For")
req.Header.Del("X-Real-IP")
req.Header.Del("X-Forwarded")
req.Header.Del("X-Original-Forwarded-For")
req.Header.Del("X-Original-Url")
req.Header.Del("X-Original-Host")

var buffer bytes.Buffer
err = req.Write(&buffer)
if err != nil {
ctx.JSON(500, exception.InternalServerError(err).ToResponse())
Expand Down Expand Up @@ -157,7 +167,8 @@ func Endpoint(
for response.Next() {
chunk, err := response.Read()
if err != nil {
ctx.JSON(500, exception.InternalServerError(err).ToResponse())
ctx.Writer.Write([]byte(err.Error()))
ctx.Writer.Flush()
return
}
ctx.Writer.Write(chunk)
Expand Down

0 comments on commit 53bd801

Please sign in to comment.