Skip to content

Commit 5a883df

Browse files
committed
Make ReadJSON secure by default
1 parent a1b12a2 commit 5a883df

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

json.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ func ReadJSON(ctx context.Context, c *Conn, v interface{}) error {
1919
return xerrors.Errorf("unexpected frame type for json (expected TextFrame): %v", typ)
2020
}
2121

22+
r.Limit(131072)
23+
r.SetContext(ctx)
24+
2225
d := json.NewDecoder(r)
2326
err = d.Decode(v)
2427
if err != nil {
@@ -31,11 +34,13 @@ func ReadJSON(ctx context.Context, c *Conn, v interface{}) error {
3134
func WriteJSON(ctx context.Context, c *Conn, v interface{}) error {
3235
w := c.MessageWriter(websocket.TextFrame)
3336
w.SetContext(ctx)
37+
3438
e := json.NewEncoder(w)
3539
err := e.Encode(v)
3640
if err != nil {
3741
return xerrors.Errorf("failed to write json: %v", err)
3842
}
43+
3944
err = w.Close()
4045
if err != nil {
4146
return xerrors.Errorf("failed to write json: %v", err)

0 commit comments

Comments
 (0)