Add header based on value in response

Hi there,

I have a cookie value that changes every five minutes or so and I need to augment Burp’s session handling to accommodate. The cookie should be copied to a header and included in all outgoing requests. Incoming requests should be monitored for updated cookies. If one is seen, the value sent in the header must also be updated.

Here’s what I’ve got so far:

from mitmproxy import http
from mitmproxy import ctx

class Bearer:
    def __init__(self):
        self.auth_token = ""

    def response(self, flow: http.HTTPFlow):
        headers = flow.response.cookies
        self.auth_token = headers.get("Authorization", "")
        self.refresh_token = headers.get("Refresh-Token", "")
        if self.auth_token:
  "Authorization Updated: {self.auth_token}")
        if self.refresh_token:
  "Refresh-Token Updated: {self.refresh_token}")

    def request(self, flow: http.HTTPFlow) -> None:        
        if self.auth_token:
            flow.request.headers["Authorization"] = self.auth_token[0]

def start():
    return Bearer()

Layer 8 issue. I don’t want to talk about it.