大网数据广告活动
服务器运维问答

Modify cookie sent from PHP in nginx

· 52CE 我爱测

I have a cookie that I need to be read in Javascript, so I need to remove the httponly part of the cookie from it. This is the cookie I need to modify: Set-Cookie: wordpress_c3d46b752402579c18e981091b8c940c=admin%7C1463963639%7CW…

问题原文

原帖链接 · IAmJulianAcosta · CC BY-SA 3.0

I have a cookie that I need to be read in Javascript, so I need to remove the httponly part of the cookie from it.

This is the cookie I need to modify:

Set-Cookie: wordpress_c3d46b752402579c18e981091b8c940c=admin%7C1463963639%7CWsIehTVJh4%7C7ee6e8117b6b; expires=Mon, 23-May-2016 12:33:59 GMT; Max-Age=1252800; path=/wp-content/plugins; domain=.example.org; HttpOnly

I just need to strip the HttpOnly string at the end of the cookie

PS: I know that I'm introducing a potential security problem here.

已采纳解答

原帖链接 · IAmJulianAcosta · CC BY-SA 3.0

This is possible using Lua:

nginx.conf:

location /foo {
    internal;
    #Do normal stuff that you will do in this location
}

location /bar {
    content_by_lua_block {
        response = ngx.location.capture("/foo")
        for cookieName, cookie in pairs(response.header["Set-Cookie"]) do
            #Modify cookie as needed
        end
    }
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。