Forum Discussion
How to properly insert HttpOnly and Secure cookie directives?
My load balancer has an iRule that adds the HttpOnly and Secure cookie directives. The rules is adding the directives multiple times, and in the incorrect places. How can I get the directives added correctly?
The rule is:
when HTTP_RESPONSE {
log local0. "from response uri: $uri"
set uri [URI::query [HTTP::uri]]
foreach cookie [HTTP::cookie names] {
if { $uri starts_with "/sputnik" or $uri starts_with "/en-us" } {
}
else {
set value [HTTP::cookie value $cookie];
if { "" != $value } {
set testvalue [string tolower $value]
set valuelen [string length $value]
log local0. "Cookie found: $cookie = $value";
switch -glob $testvalue {
"*;secure*" -
"*; secure*" { }
default { set value "$value; Secure"; }
}
switch -glob $testvalue {
"*;httponly*" -
"*; httponly*" { }
default { set value "$value; HttpOnly"; }
}
if { [string length $value] > $valuelen} {
log local0. "Replacing cookie $cookie with $value"
HTTP::cookie value $cookie "${value}"
}
}
}
}
}
}
`
Cookies from the host look like:
`Set-Cookie: sso.auth_token=deleted; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/
`
Cookies through the load balancer look like:
`Set-Cookie: sso.auth_token=deleted; Secure; HttpOnly; Expires=Thu,; Secure; HttpOnly 01-Jan-1970 00:00:10; Secure; HttpOnly GMT; Path=/
`
I _expect_ cookies through the load balancer to look like:
`Set-Cookie: sso.auth_token=deleted; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; Secure; HttpOnly
Is there something in the iRule that could make it add the directives multiple times, an in the incorrect place?
I am not very familiar with F5 load balancers. If the shown iRule isn't causing the issue, where else would you recommend I look?
Addition: The iRules are running on LTM v11.2
23 Replies
- Jason_AdamsRet. Employee
If you have reached this discussion and are still looking for a solution; this one is worth a read:
How to add Httponly and Secure attributes to HTTP cookies (for 11.5.x)
- Koen_Liu_132842
Nimbostratus
Hi All,
I have also struggled with the httponly and secure attributes with a i-rule without any results. Until i found the setting within ASM, Headers cookie list, put in a wildcard and inject the 2 attribute
Stop trying to do this with an i-rule just use ASM.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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
