coderjay
coderjay

Reputation: 41

Burp Extension: add header to response

Burp newbie writing an extension... I am trying to add a header to the response to test CSP rules. I have found lots of resources to add headers to Requests, but not for Responses. Here is the (non-working) code I have so far:

def processHttpMessage(self, toolFlag, messageIsRequest, messageInfo):

    # determine what tool we would like to pass though our extension:
    if toolFlag == 4: #if tool is Proxy Tab
        # determine if request or response:
        if not messageIsRequest:#only handle responses
            response = messageInfo.getResponse() #get Response from IHttpRequestResponse instance
            responseStr = self._callbacks.getHelpers().bytesToString(response)
            responseParsed = self._helpers.analyzeResponse(response)
            body = responseStr[responseParsed.getBodyOffset():]
            headers = responseParsed.getHeaders()

            headers.add('MYHEADER: TEST')

            httpResponse = self._callbacks.getHelpers().buildHttpMessage(headers, body)
            return

Upvotes: 1

Views: 6475

Answers (1)

Cynic
Cynic

Reputation: 7266

I think you found an extension but you can just do this in the standard version of the program.

Proxy Tab > 2nd row of tabs Options > scroll down to Match and Replace > Hit Add > Change Type to Response Header, Put the new header in Replace. And as the default text says in Match 'leave blank to add a new header'

Upvotes: 10

Related Questions