Skip to content

Commit 72270be

Browse files
committed
fsthttp: ensure OverrideKey has the correct format
1 parent 0b39b3c commit 72270be

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fsthttp/request.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package fsthttp
55
import (
66
"bytes"
77
"context"
8+
"encoding/hex"
89
"errors"
910
"fmt"
1011
"io"
@@ -516,6 +517,9 @@ func (req *Request) sendWithGuestCache(ctx context.Context, backend string) (*Re
516517

517518
var options fastly.HTTPCacheLookupOptions
518519
if key := req.CacheOptions.OverrideKey; key != "" {
520+
if len(key) != 32 {
521+
return nil, fmt.Errorf("bad length for OverrideKey: %v != 32", len(key))
522+
}
519523
options.OverrideKey(key)
520524
req.CacheOptions.OverrideKey = ""
521525
}
@@ -841,6 +845,13 @@ func (req *Request) setABIRequestOptions() error {
841845
}
842846

843847
if key := req.CacheOptions.OverrideKey; key != "" {
848+
if len(key) != 32 {
849+
return fmt.Errorf("bad length for OverrideKey: %v != 32", len(key))
850+
}
851+
852+
// the header must be 64-byte upper-case hex encoded
853+
key = strings.ToUpper(hex.EncodeToString([]byte(key)))
854+
844855
if err := abiReq.SetHeaderValues("fastly-xqd-cache-key", []string{key}); err != nil {
845856
return fmt.Errorf("set headers cache-key: %w", err)
846857
}

0 commit comments

Comments
 (0)