feat: enhance anonProxyHandler to handle binary data safely

- Added Base64 encoding for the response body in the anonProxyHandler to prevent corruption of binary data when returned in JSON format.
- Updated the response structure to include the encoded body, ensuring compatibility with various data types.
This commit is contained in:
anonpenguin23 2025-10-30 09:00:24 +02:00
parent fe16d503b5
commit 351ce086bf
3 changed files with 20 additions and 5 deletions

View File

@ -10,6 +10,18 @@ The format is based on [Keep a Changelog][keepachangelog] and adheres to [Semant
### Changed ### Changed
### Deprecated
### Fixed
## [0.52.15]
### Added
- Added Base64 encoding for the response body in the anonProxyHandler to prevent corruption of binary data when returned in JSON format.
### Changed
- **GoReleaser**: Updated to build only `network-cli` binary (v0.52.2+) - **GoReleaser**: Updated to build only `network-cli` binary (v0.52.2+)
- Other binaries (node, gateway, identity) now installed via `network-cli setup` - Other binaries (node, gateway, identity) now installed via `network-cli setup`
- Cleaner, smaller release packages - Cleaner, smaller release packages
@ -155,7 +167,6 @@ The format is based on [Keep a Changelog][keepachangelog] and adheres to [Semant
### Fixed ### Fixed
## [0.50.0] - 2025-09-23 ## [0.50.0] - 2025-09-23
### Added ### Added
@ -286,4 +297,3 @@ _Initial release._
[keepachangelog]: https://keepachangelog.com/en/1.1.0/ [keepachangelog]: https://keepachangelog.com/en/1.1.0/
[semver]: https://semver.org/spec/v2.0.0.html [semver]: https://semver.org/spec/v2.0.0.html

View File

@ -21,7 +21,7 @@ test-e2e:
.PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports .PHONY: build clean test run-node run-node2 run-node3 run-example deps tidy fmt vet lint clear-ports
VERSION := 0.52.14 VERSION := 0.52.15
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown) COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ) DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)' LDFLAGS := -X 'main.version=$(VERSION)' -X 'main.commit=$(COMMIT)' -X 'main.date=$(DATE)'

View File

@ -1,6 +1,7 @@
package gateway package gateway
import ( import (
"encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@ -176,11 +177,15 @@ func (g *Gateway) anonProxyHandler(w http.ResponseWriter, r *http.Request) {
zap.Int("bytes", len(respBody)), zap.Int("bytes", len(respBody)),
zap.Duration("duration", duration)) zap.Duration("duration", duration))
// Base64-encode the body to safely handle binary data in JSON
// This prevents corruption when binary data is converted to a string
bodyBase64 := base64.StdEncoding.EncodeToString(respBody)
// Return the proxied response // Return the proxied response
writeJSON(w, http.StatusOK, anonProxyResponse{ writeJSON(w, http.StatusOK, anonProxyResponse{
StatusCode: resp.StatusCode, StatusCode: resp.StatusCode,
Headers: respHeaders, Headers: respHeaders,
Body: string(respBody), Body: bodyBase64,
}) })
} }