nlzy
V2EX  ›  问与答

为什么有些 cookie 在 JavaScript 用 document.cookie 读不出来

  •  
  •   nlzy · Apr 15, 2015 · 8005 views
    This topic created in 4236 days ago, the information mentioned may be changed or developed.

    http://i.imgur.com/m7MeUDw.jpg

    console 里输入 document.cookie,不返回 wordpress_logged 开头的 cookie

    如果要读取那个 cookie 要怎么做

    5 replies  •  2015-04-15 11:36:32 +08:00
    caomu
    caomu
    Apr 15, 2015 via Android
    1
    手机码字不便。关键词 http only cookies 。
    要获取这些饼干,用浏览器的api。
    virusdefender
    virusdefender
    Apr 15, 2015
    2
    http only的吧
    NewYear
    NewYear
    Apr 15, 2015
    3
    楼主你好,cookie有一个选项是httponly属性,这个属性如果标记上去的话,就是不允许js去读写的。以此避免XSS。只有服务器端可以读取写(当然你说浏览器插件之类那就另当别论了)
    NewYear
    NewYear
    Apr 15, 2015
    4
    接楼上,你这里没有体现出这个httponly属性,我特别去看了我的wordpress,你在开发者工具,Resource>Cookies就可以看到有个HTTP的属性。
    nlzy
    nlzy
    OP
    Apr 15, 2015
    5
    @caomu @virusdefender @NewYear 嗯,我查了查 ,发现的确是httponly的,我以前还真的不知道有这个属性呢,多谢帮助:-)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1276 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 17:27 · PVG 01:27 · LAX 09:27 · JFK 12:27
    ♥ Do have faith in what you're doing.