Hi @dchiesa1 ,
sorry for not been clear earlier.
Basically, our scenario is this:
-
on all our authenticated APIs we have a pre request shared flow that depending on scenario can refresh the tokens with new values, which need to be set to the browser once the backend API is called. The backend API is legacy and cannot handle these tokens. The refresh action is performed via a service callout policy.
-
authentication depends on 3rd party SaaS solution and was currently setting the cookies using Expires attribute (there are at least 4 cookies)
-
once the backend has been invoked we have a post response shared flow that checks if authentication tokens have been refreshed and if so then we set all the Set-Cookie headers on the main API response.
The issue we found first was that on the pre request shared flow when we were trying to store the new set-cookies into a variable, it was storing (erroneously) double the number of cookies because of the comma separator on Expires. We have applied a workaround by storing the raw value (servicecalloutcontext.header.set-cookie.values.string)
Now the second issue is that on the final policy that injects the Set-Cookie headers when we try to accommodate the set-cookie separately for e.g.
context.setVariable('response.header.Set-Cookie.1', 'xxxx_it=eyJ0A; Domain=.xpto.com; Path=/; Expires=Sat, 22 Mar 2025 14:46:00 GMT; Secure; SameSite=Strict'); context.setVariable('response.header.Set-Cookie.2', '28e67=; Domain=.xpto.com; Path=/; Expires=Sat, 22 Mar 2025 14:46:00 GMT; HttpOnly; Secure; SameSite=Strict'); context.setVariable('response.header.Set-Cookie.3', 'xxxx_at=U5OhG4zHZM; Domain=.xpto.com; Path=/; Expires=Sat, 22 Mar 2025 14:46:00 GMT; HttpOnly; Secure; SameSite=Strict');
is that it returns a single folded Set-Cookie response header on Postman - this makes the browser set only the first cookie and ignores the other cookies.
We did some hard coding to understand what Apigee was doing and found out the same is again related with the comma (,) on the Expires attribute, given that if we hard code following example (no commas on the expire attribute):
context.setVariable('response.header.Set-Cookie.1', 'xxxx_it=eyJ0A; Domain=.xpto.com; Path=/; **Expires=22 Mar 2025 14**:46:00 GMT; Secure; SameSite=Strict'); context.setVariable('response.header.Set-Cookie.2', '28e67=; Domain=.xpto.com; Path=/; **Expires=22 Mar 2025 14:46:00** GMT; HttpOnly; Secure; SameSite=Strict'); context.setVariable('response.header.Set-Cookie.3', 'xxxx_at=U5OhG4zHZM; Domain=.xpto.com; Path=/; **Expires=22 Mar 2025** 14:46:00 GMT; HttpOnly; Secure; SameSite=Strict');
it will generate three Set-Cookie response headers on Postman.
The quick fix for this was to replace Expires attribute by Max-Age attribute. As I followed other threads on Apigee community and read about the latest RFCs, the expires should be replaced by Max-Age.
My concern was if the project were actually asking to maintain the expires attribute, however we got confirmation this morning they will be replacing the cookie generation to use Max-Age instead, so we are all good on this.
However the concern was if we needed to maintain the Expires attribute (given Max-Age is not supported on very old browsers like IE, etc..).
Also the other point you brought was about set-cookie folding or combining multiple set-cookie headers into one. We found some discussion on stackoverflow that points to https://www.rfc-editor.org/rfc/rfc6265 section 3 that states that…
Origin servers SHOULD NOT fold multiple Set-Cookie header fields into a single header field. The usual mechanism for folding HTTP headers fields (i.e., as defined in [[RFC2616](https://www.rfc-editor.org/rfc/rfc2616)]) might change the semantics of the Set-Cookie header field because the %x2C (",") character is used by Set-Cookie in a way that conflicts with such folding.
Errata version:
Origin servers SHOULD NOT combine multiple Set-Cookie header fields into a single header field. The usual mechanism for combining HTTP headers fields (i.e., as defined in [RFC2616]) might change the semantics of the Set-Cookie header field because the %x2C (",") character is used by Set-Cookie in a way that conflicts with such actions.
So in some way I see a point to fix this in Apigee code however given we have a workaround this is no longer a priority for us.
Also I agree this is the problem of maintaining compatibility support with very old versions, specs, etc.. We should all look into the “blue sky scenario” and discard all previous assumption. But you also understand where we are coming from.
Thanks.