Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to append SameSite=None to Set-Cookie?#11975

Unanswered
rohitkrishna-marneni asked this question inQ&A
Discussion options

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?

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

Hey@rohitkrishna-marneni! 👋 I'm here to help you with any bugs, questions, or contributions you have. Let's tackle this together!

Currently, theresponse-rewrite plugin in APISIX allows you to set or overwrite headers, includingSet-Cookie headers, but it does not support appending attributes to existing cookies without overwriting other attributes. This means that when you use theset option, it replaces the entireSet-Cookie header, which is why the original settings likepath=/ are being overridden.

Unfortunately, there isn't a built-in feature in APISIX to dynamically append attributes likeSameSite=None to all cookies in a response without specifying each cookie individually. You would need to handle this logic externally or modify the plugin to support such functionality.

If you need to applySameSite=None to all cookies, you might consider implementing a custom plugin or using a Lua script to parse and modify theSet-Cookie headers as needed.

To continue talking toDosu, mention@dosu.


Help Dosu learn! Give it feedback:Great Response |Irrelevant Answer |Incorrect Sources |Too Verbose |Hallucination |Bug Report |Other

You must be logged in to vote
0 replies
Comment options

@dosu How to write a plugin for this usecase?

You must be logged in to vote
1 reply
@dosubot
Comment options

To write a custom plugin in APISIX for appendingSameSite=None to allSet-Cookie headers, follow these steps:

  1. Create the Plugin File: Place your plugin in theapisix/plugins directory. For example, create a file namedset_cookie_samesite.lua.

  2. Define the Plugin Structure: Implement the necessary methods for your plugin, such asschema,check_schema, andheader_filter.

  3. Modify theSet-Cookie Headers: Use theheader_filter phase to iterate over theSet-Cookie headers and appendSameSite=None to each one.

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
  1. Configure APISIX: Add your plugin to theconfig.yaml file under theplugins section to ensure it is loaded by APISIX.

  2. Test Your Plugin: Deploy your plugin and test it by making requests to your service to ensure that theSet-Cookie headers are modified as expected.

By following these steps, you can create a custom plugin to appendSameSite=None to allSet-Cookie headers in APISIX.

To continue talking toDosu, mention@dosu.


Help Dosu learn! Give it feedback:Great Response |Irrelevant Answer |Incorrect Sources |Too Verbose |Hallucination |Bug Report |Other

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@rohitkrishna-marneni

[8]ページ先頭

©2009-2025 Movatter.jp