Mitmproxy multiple cookie headers

Viewed 66

I'm attempting to modify a saved flow's cookie and resend it, but the captured flow has multiple "cookie" headers.

cookie: uuid=3AF89B5E-1162-4236-B60D-6E4B05177A14
cookie: fp_token_7c6a6574-f011-4c9a-abdd5l05EcWM3T5o/whEw=
cookie: _gsid=84c8326882b6a81bad5

The goal is to update just one of the three values. Attempts to set the cookie via flow.request.headers["cookie"]="NEWVALUEHERE;fp_token_7c6a6574-f011-4c9a-abdd5l05EcWM3T5o/whEw=;_gsid=84c8326882b6a81bad5;" results in the flow collapsing the three different cookie headers into one header, which the server doesn't accept.

print(flow.request.headers)

Headers[(b'cookie', b's=3AF89B5E-1162-4236-B60D-6E4B05177A14'), (b'cookie', b'fp_token_7c6a6574-d-9894a102cOA5l05EcWM3T5o/whEw='), (b'cookie', b'_gsid=84c83268866a81bad5')]

Any help would be appreciated. Thanks!

1 Answers

You can use Headers.set_all:

flow.request.headers.set_all(
    "cookie", 
    ["first cookie", "second cookie", "third cookie"]
)
Related