Hi,
The following iRule is working fine to encrypt and set secure flag. Currently running on 11.2.1 HF13.
When adding HttpOnly flag we are receiving the following errors:
- Improper version (line 9) invoked from within “HTTP::cookie httponly $cookie_name enable” (“foreach” body line 18) invoked from within “foreach cookie_name $cookie_names { if {$static::ck_debug}{log local0. “Cookie Name unencryted : $cookie_name”} Encrypt the cookie value …”
Which causes overall failure and errors. Version is added before enabling HttpOnly.
Is there a bug? Code issue?
How can I ensure HttpOnly flag is also being set on the all BIGipServer cookies (We have multiple due to web and app layers)?
Thanks J
when RULE_INIT {
Cookie name prefix
set static::ck_pattern "BIGipServer*"
Log debug to /var/log/ltm? 1=yes, 0=no)
set static::ck_debug 1
Cookie encryption passphrase 20 chars
The default key length is 128 AES
set static::ck_pass "XXXXXXXX"
}
when HTTP_REQUEST {
if {$static::ck_debug}{log local0. "Request cookie names: [HTTP::cookie names]"}
Check if the cookie names in the request match our string glob pattern
if {[set cookie_names [lsearch -all -inline [HTTP::cookie names] $static::ck_pattern]] ne ""}{
We have at least one match so loop through the cookie(s) by name
if {$static::ck_debug}{log local0. "Matching cookie names: [HTTP::cookie names]"}
foreach cookie_name $cookie_names {
Decrypt the cookie value and check if the decryption failed (null return value)
if {[HTTP::cookie decrypt $cookie_name $static::ck_pass] eq ""}{
Cookie wasn't encrypted, delete it
if {$static::ck_debug}{log local0. "Removing cookie as decryption failed for $cookie_name"}
HTTP::cookie remove $cookie_name
}
}
if {$static::ck_debug}{log local0. "Cookie header(s): [HTTP::header values Cookie]"}
}
}
when HTTP_RESPONSE {
if {$static::ck_debug}{log local0. "Response cookie names: [HTTP::cookie names]"}
Check if the cookie names in the request match our string glob pattern
[lsearch -all -inline [split [HTTP::cookie names]] $static::ck_pattern]
if {[set cookie_names [lsearch -all -inline [HTTP::cookie names] $static::ck_pattern]] ne ""}{
We have at least one match so loop through the cookie(s) by name
if {$static::ck_debug}{log local0. "Matching cookie names: [HTTP::cookie names]"}
foreach cookie_name $cookie_names {
if {$static::ck_debug}{log local0. "Cookie Name unencryted : $cookie_name"}
Encrypt the cookie value
HTTP::cookie encrypt $cookie_name $static::ck_pass
if {$static::ck_debug}{log local0. "Cookie Name encryted : $cookie_name"}
Secure Cookie flag
HTTP::cookie secure $cookie_name enable
if {$static::ck_debug}{log local0. "Add secure : $cookie_name"}
HttpOnly flag - v11+ only
HTTP::cookie version $cookie_name 1
HTTP::cookie httponly $cookie_name enable
if {$static::ck_debug}{log local0. "Add httponly : $cookie_name"}
}
if {$static::ck_debug}{log local0. "Set-Cookie header(s): [HTTP::header values Set-Cookie]"}
}
}