Skip to content

Commit 7d1b4ad

Browse files
committed
Verify the 413 body as JSON and use engine terminology in the docs
The oversized-body test now unmarshals the 413 response and asserts the exact error payload instead of substring-matching, so the response can never silently stop being valid JSON. docs/proxy-request-hardening.mdx uses engine where the prose means the engine address rather than the set-local-backend wire name, and the sequence diagram shows the 413 payload as the JSON it is. Signed-off-by: Mallikh Kaula <mallikh@users.noreply.github.com>
1 parent 229769d commit 7d1b4ad

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎docs/proxy-request-hardening.mdx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ sequenceDiagram
5757
The proxy never holds more than cap+1 bytes per in-flight request body, so a
5858
malicious or buggy client can no longer exhaust proxy memory.
5959

60-
## 2. The local backend must be loopback
60+
## 2. The local engine address must be loopback
6161

6262
### The problem
6363

@@ -71,7 +71,7 @@ approved.
7171

7272
### The fix
7373

74-
The unified ingress enforces the invariant where the backend is stored:
74+
The unified ingress enforces the invariant where the engine address is stored:
7575
`setLocalBackend()` in `ingress.go` refuses a non-loopback host outright and
7676
returns an error, so a bad value never reaches the dial path at all.
7777

@@ -85,7 +85,7 @@ flowchart TD
8585
A[broker: set-local-backend] --> B{host empty?}
8686
B -->|yes| C[store, default 127.0.0.1 at dial time]
8787
B -->|no| D{ParseIP → IsLoopback?}
88-
D -->|yes| E[store backend]
88+
D -->|yes| E[store engine address]
8989
D -->|no| F[refuse: return error<br/>nothing stored]
9090
```
9191

@@ -130,7 +130,7 @@ longer downgrade to an unauthenticated connection in the meantime.
130130
## Validation
131131

132132
- `proxy_hardening_test.go` covers all three fixes: over-cap and at-cap
133-
bodies, the 413 response shape, loopback/non-loopback backend hosts, and
133+
bodies, the 413 response shape, loopback/non-loopback engine hosts, and
134134
the fail-closed dial error. Run with `go test -race ./...` from the
135135
component directory.
136136
- No JSON-RPC method or payload changed, so no contract regeneration was

‎services/nvpair-proxy/proxy_hardening_test.go‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package main
55

66
import (
7+
"encoding/json"
78
"io"
89
"net/http"
910
"net/http/httptest"
@@ -67,8 +68,12 @@ func TestHandleHTTPRejectsOversizedBody(t *testing.T) {
6768
if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
6869
t.Errorf("Content-Type = %q, want application/json", ct)
6970
}
70-
if !strings.Contains(rec.Body.String(), "request body exceeds") {
71-
t.Errorf("413 body = %q, want it to name the limit", rec.Body.String())
71+
var payload map[string]string
72+
if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {
73+
t.Fatalf("413 body is not valid JSON: %v (body = %q)", err, rec.Body.String())
74+
}
75+
if payload["error"] != "request body exceeds 32 MiB limit" {
76+
t.Errorf("413 error = %q, want %q", payload["error"], "request body exceeds 32 MiB limit")
7277
}
7378
}
7479

0 commit comments

Comments
 (0)