0

When using python I am unable to log the cookies associated with a request made to an application which adds a JSESSIONID to my request. Meanwhile accessing the same URL with curl or a browser does.

RHEL 7.6, Tomcat 8.5.51 server.xml includes

<Valve className="org.apache.catalina.valves.AccessLogValve" ... JSESSIONID:%{JSESSIONID}c... />

python

>>>import requests
>>>requests.__version__
'2.22.0'
>>>s = requests.Session()
>>>r = s.get(url, verify=False)
>>>for h in r.headers:
...    print(h + ":" + r.headers[h])

yields "Set-Cookie:JSESSIONID=7FEC20ECDEA11AC01A14A9346E26B9C3; Path=/xyz; Secure; HttpOnly"

and

>>>for c in s.cookies:
...    print(c)

yields "<Cookie JSESSIONID=7FEC20ECDEA11AC01A14A9346E26B9C3 for server/xyz>"

However, my access log always shows "JSESSIONID:-" following my request.

Any ideas?

Corp SE
  • 71
  • 2
  • 6

1 Answers1

0

It looks like I just needed to pay a little more attention to the redirects which were taking place in the browser and with curl. Making a second request to the same URL in the same session allowed the cookies to be logged from python.

Another option that worked was to configure my pattern to log %{Set-Cookie}o so that only a single request was necessary.

Corp SE
  • 71
  • 2
  • 6