Mobile app version of vmapp.org
Login or Join
Murphy175

: Enforcing a specific order for cookie headers We have an application that cares about the order of cookie headers. It shouldn't, since this isn't mandated by the standards and indeed we're getting

@Murphy175

Posted in: #Apache #Cookie #HttpHeaders

We have an application that cares about the order of cookie headers. It shouldn't, since this isn't mandated by the standards and indeed we're getting the headers in various different orders

So we would like to rewrite the headers in Apache so that the cookie headers always appear in a specific order. Is there any way of doing this?

An ideal solution would be specifically about cookie headers, but something that lets us mess with the header order more generally would do too.

EDIT: Turns out this may be a red herring and it's actually a problem with the format of the cookie: line produced by the embedded system (sometimes). But this is still useful stuff to know

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Murphy175

1 Comments

Sorted by latest first Latest Oldest Best

 

@XinRu657

You could read the values of the cookies into ENV variables, unset the headers using mod_headers RequestHeader directives, and then set the headers again.

Update: Solution for reading cookie values into ENV vars and then manipulating headers to control Set-Cookie header order.

<IfModule mod_rewrite.c>
RewriteEngine on

# Read cookie1 into ENV:COOKIE1
RewriteCond %{HTTP_COOKIE} cookie1=([^;]+) [NC]
RewriteRule (.*) - [E=COOKIE1:%1]

# Read cookie2 into ENV:COOKIE2
RewriteCond %{HTTP_COOKIE} cookie2=([^;]+) [NC]
RewriteRule (.*) - [E=COOKIE2:%1]

</IfModule>

<IfModule mod_headers.c>
Header set Set-Cookie "cookie1=%{COOKIE1}e; path=/;" env=COOKIE1
Header set Set-Cookie "cookie2=%{COOKIE2}e; path=/;" env=COOKIE2
</IfModule>


Tested and working on my configuration (you can experiment by swapping the Header set Set-Cookie directives).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme