- Notifications
You must be signed in to change notification settings - Fork2.6k
How to append SameSite=None to Set-Cookie?#11975
-
I have an endpoint which returns a set of cookies. However I need to append(or modify) these cookies so that they have SameSite=None attribute set. More aboutSameSite. So I have my yml configuration like this. services: -name:my-serviceupstream:# my upstream informationname:my-upstream#...routes: -name:my-first-routehosts: -"my-service.com"uris: -/my-serviceplugins:response-rewrite:body_base64:falseheaders:set:Set-Cookie:"uuid=12345; SameSite=None" I am able to modify the cookie uuid, however its actual settings like path=/ is being overriden. Also with this approach I can only append SameSite=None to one cookie(which is uuid in my case). However I want to append SameSite=None to all my cookies which are sent in set-cookie header after a call to endpoint /my-service. Is there a way to do it in apisix? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 2 comments 1 reply
-
Hey@rohitkrishna-marneni! 👋 I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this together! Currently, the Unfortunately, there isn't a built-in feature in APISIX to dynamically append attributes like If you need to apply To continue talking toDosu, mention@dosu. Help Dosu learn! Give it feedback:Great Response |Irrelevant Answer |Incorrect Sources |Too Verbose |Hallucination |Bug Report |Other |
BetaWas this translation helpful?Give feedback.
All reactions
-
@dosu How to write a plugin for this usecase? |
BetaWas this translation helpful?Give feedback.
All reactions
-
To write a custom plugin in APISIX for appending
Here's a basic example of how your plugin might look: localcore=require("apisix.core")localplugin_name="set_cookie_samesite"localschema= {type="object",properties= {},}local_M= {version=0.1,priority=1000,-- Set a priority for your pluginname=plugin_name,schema=schema,}function_M.check_schema(conf)returncore.schema.check(schema,conf)endfunction_M.header_filter(conf,ctx)localset_cookie=core.response.get_header("Set-Cookie")ifnotset_cookiethenreturnendiftype(set_cookie)=="string"thenset_cookie= {set_cookie}endfori,cookieinipairs(set_cookie)doifnotcookie:find("SameSite")thenset_cookie[i]=cookie.."; SameSite=None"endendcore.response.set_header("Set-Cookie",set_cookie)endreturn_M
By following these steps, you can create a custom plugin to append To continue talking toDosu, mention@dosu. Help Dosu learn! Give it feedback:Great Response |Irrelevant Answer |Incorrect Sources |Too Verbose |Hallucination |Bug Report |Other |
BetaWas this translation helpful?Give feedback.