Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to modify request headers on TLS connection #1418

Closed
sandrich opened this issue Jun 7, 2024 · 4 comments
Closed

How to modify request headers on TLS connection #1418

sandrich opened this issue Jun 7, 2024 · 4 comments
Labels
Question Questions related to proxy server

Comments

@sandrich
Copy link

sandrich commented Jun 7, 2024

Hi,

I have been trying to modify the request headers when using a TLS endpoint. The goal is to modify/annotate headers before it gets forwarded to the downstream connection.

With pure http this works just fine

class FsProxyPlugin(HttpProxyBasePlugin):
    def before_upstream_connection(
            self, request: HttpParser,
    ) -> Optional[HttpParser]:
        request.add_header(b'test-header', b'bla')


        return request
curl -x localhost:8899  http://httpbin.org/get 
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Host": "httpbin.org", 
    "Test-Header": "bla", 
    "User-Agent": "curl/8.6.0", 
    "X-Amzn-Trace-Id": "Root=1-6663010e-67beef541cb0758024297e78"
  }, 
  "url": "http://httpbin.org/get"
}

vs

curl -x localhost:8899 --cacert ca-cert.pem https://httpbin.org/get
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/8.6.0", 
    "X-Amzn-Trace-Id": "Root=1-66630130-5908034b3c98368153643828"
  }, 
  "url": "https://httpbin.org/get"
}

I am starting with

if __name__ == "__main__":

    with proxy.Proxy(
        input_args=[
            "--threaded",
            "--proxy-config='{}'",
            "--ca-key-file=/Users/chrissandrini/dev/proxy.py/ca-key.pem",
            "--ca-cert-file=/Users/chrissandrini/dev/proxy.py/ca-cert.pem",
            "--ca-signing-key-file=/Users/chrissandrini/dev/proxy.py/ca-signing-key.pem",
            "--ca-file=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/certifi/cacert.pem"
        ],
        plugins=[FsProxyPlugin]
    ) as _:
        proxy.sleep_loop()
@abhinavsingh
Copy link
Owner

@sandrich Do you mean modification of request headers is not working under TLS interception mode?

@sandrich
Copy link
Author

sandrich commented Jun 9, 2024

yes correct @abhinavsingh . I am trying to modify the request headers before forwarding the request.

@abhinavsingh
Copy link
Owner

@abhinavsingh abhinavsingh added the Question Questions related to proxy server label Jun 9, 2024
@sandrich
Copy link
Author

Amazing thanks for that. Is a self signed CA actually required to add headers to the request? Since in our environment self signed CAs are not allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Questions related to proxy server
Projects
None yet
Development

No branches or pull requests

2 participants