最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Users can set cookies in console? - Stack Overflow

programmeradmin2浏览0评论

I'm wondering the best way to implement cookies to my site. I would like a user to be able to edit a given post based off a cookie that I set at the time the post is created.

I'm using Angular to set the cookie. ie:

var favoriteCookie = $cookies.myFavorite;
$cookies.myFavorite = 'oatmeal';

(per the Angular tutorial for $cookies).

My question is more at the core of how to use cookies. Wouldn't it be easy for a user to set the cookie using the console? ie:

 document.cookie = 'key=value';

And get access to a post for editing? Perhaps I should be creating a unique id to use as a cookie that I then check for when the actual creator visits the page? If so, how might I go about this to best ensure only the actual creator of the post has access to editing?

I'm wondering the best way to implement cookies to my site. I would like a user to be able to edit a given post based off a cookie that I set at the time the post is created.

I'm using Angular to set the cookie. ie:

var favoriteCookie = $cookies.myFavorite;
$cookies.myFavorite = 'oatmeal';

(per the Angular tutorial for $cookies).

My question is more at the core of how to use cookies. Wouldn't it be easy for a user to set the cookie using the console? ie:

 document.cookie = 'key=value';

And get access to a post for editing? Perhaps I should be creating a unique id to use as a cookie that I then check for when the actual creator visits the page? If so, how might I go about this to best ensure only the actual creator of the post has access to editing?

Share Improve this question asked May 13, 2015 at 0:43 arahansenarahansen 1172 gold badges3 silver badges12 bronze badges 1
  • Are you handle sessions? – MelgoV Commented May 13, 2015 at 0:47
Add a ment  | 

1 Answer 1

Reset to default -1

You can restrict JavaScript manipulation by setting the HttpOnly flag in the cookie on a response. The console won't be able to set it programatically.

发布评论

评论列表(0)

  1. 暂无评论