I have a cookie that is NOT HttpOnly
Can I set this cookie to HttpOnly
via JavaScript?
相关问题
- Angular RxJS mergeMap types
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
A
HttpOnly
cookie means that it's not available to scripting languages like JavaScript. So there's in JavaScript absolutely no API available to get/set theHttpOnly
attribute of the cookie, as that would otherwise defeat the meaning ofHttpOnly
.Just set it as such in the server side using whatever server side language the server side is using. If JavaScript is absolutely necessary in this, you could consider to just let it send some (ajax) request with e.g. some specific request parameter which triggers the server side language to create a HttpOnly cookie. But, that would still make it easy for hackers to change the
HttpOnly
by just XSS and still have access to the cookie via JS and thus make theHttpOnly
on your cookie completely useless.