Forum Discussion
hoolio
Cirrostratus
Dec 14, 2007Manipulating a decrypted cookie value using HTTP::cookie decrypt
Hi,
I'm running into an issue on 9.2.4 when trying to get and potentially manipulate the unencrypted value of a cookie. I encrypt the cookie sent in the response using HTTP::cookie encrypt and then use this code in the HTTP_REQUEST event to decrypt it:
if {$::error_cookie_debug}{log local0. "Original error cookie value: [HTTP::cookie value $::error_cookie]"}
HTTP::cookie decrypt $::error_cookie $::cookie_pass 128
if {$::error_cookie_debug}{log local0. "Decrypted error cookie value: [HTTP::cookie value $::error_cookie]"}
The log output shows the encrypted value for both log entries:
Original error cookie value: hPMuQ/vZ3BwWZhe71UizCYaIirs0LFB3vKtchKRLWZGSNjLH
Decrypted error cookie value: hPMuQ/vZ3BwWZhe71UizCYaIirs0LFB3vKtchKRLWZGSNjLH
Is this because the cookie value is being cached? If so, is there a way to get the value of the decrypted cookie?
As a workaround, I've had to use AES::encrypt to set the value of the cookie in the response and then use AES::decrypt on the subsequent request. This limits the value of the HTTP::cookie encrypt/decrypt functions though.
Thanks in advance for any suggestions.
Aaron
- Patrick_Chang_7Historic F5 AccountThe documentation indicates that HTTP::cookie decrypt returns the decrypted cookie value. It does not change the input cookie. Try this:
- hoolio
Cirrostratus
Hi pchang, - hoolio
Cirrostratus
Actually, it does look like the cookie value is modified by the encrypt and decrypt functions. I was getting confused by the HTTP::header and HTTP::cookie values being cached. You can decrypt the cookie value and save the output to a variable to workaround the problem with difficulty of cached values.when RULE_INIT { set ::cookie_passphrase "some phrase" set ::cookie_name "cookie_name" set ::cookie_value "cookie_value" } when HTTP_REQUEST priority 500 { HTTP::cookie insert name $::cookie_name value $::cookie_value log local0. "500 Unencrypted cookie value: [HTTP::cookie value $::cookie_name]" Encrypt cookie and save the encrypted value set encrypted_value [HTTP::cookie encrypt $::cookie_name $::cookie_passphrase] log local0. "500 \$encrypted_value: $encrypted_value" log local0. "500 Correct cookie header value: [HTTP::header value Cookie]" log local0. "500 Cached cookie value: [HTTP::cookie value $::cookie_name]" } when HTTP_REQUEST priority 501 { log local0. "501 Encrypted test cookie value: [HTTP::cookie value $::cookie_name]" log local0. "501 Cookie header with encrypted value: [HTTP::header value Cookie]" } when HTTP_REQUEST priority 502 { Encrypt cookie and save the encrypted value set decrypted_value [HTTP::cookie decrypt $::cookie_name $::cookie_passphrase] log local0. "502 \$decrypted_value: $decrypted_value" log local0. "502 Decrypted cookie header value: [HTTP::header value Cookie]" log local0. "502 Decrypted cookie value: [HTTP::cookie value $::cookie_name]" }
: 500 Unencrypted cookie value: cookie_value: 500 $encrypted_value: f3lzsw7kqxIeu2vI6yy8eCITlBtuGboyFJ5D1ES0tzpxA98XJ90P: 500 Correct cookie header value: cookie_name=f3lzsw7kqxIeu2vI6yy8eCITlBtuGboyFJ5D1ES0tzpxA98XJ90P;: 500 Cached cookie value: cookie_value: 501 Encrypted test cookie value: f3lzsw7kqxIeu2vI6yy8eCITlBtuGboyFJ5D1ES0tzpxA98XJ90P: 501 Cookie header with encrypted value: cookie_name=f3lzsw7kqxIeu2vI6yy8eCITlBtuGboyFJ5D1ES0tzpxA98XJ90P;: 502 $decrypted_value: cookie_value: 502 Decrypted cookie header value: cookie_name=cookie_value;: 502 Decrypted cookie value: cookie_value
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects