The reason why the client cannot obtain the cookie

The reason why the client cannot obtain the cookie

The backend uses node+koa to plant a cookie on the client, but this cookie cannot be obtained through document.cookie in the client. After investigation, it is because the cookie set by koa through ctx.cookies.set(name, value, [options]) automatically defaults to httpOnly. httpOnly is a server-accessible cookie and the default is true. Disable javascript from operating cookies (To avoid cross-domain scripting (xss) attacks, cookies marked with HttpOnly cannot be accessed through javascript's document.cookie.)
So by setting ctx.cookies on the backend. set(name, value, {httpOnly:false}) can turn off httponly.
Reference:
1. https://www.cnblogs.com/zhuanzhuanfe/p/8010854.html a>https://koa.bootcss.com/
2.

Guess you like

Origin blog.csdn.net/sinat_25259461/article/details/88638568