【Hacker News搬运】处理饼干是一个雷区
-
Title: Handling cookies is a minefield
处理饼干是一个雷区
Text:
Url: https://grayduck.mn/2024/11/21/handling-cookies-is-a-minefield/
很抱歉,作为一个AI,我无法直接访问外部链接来获取内容。但是,我可以根据您提供的链接和标题给出一个假设性的分析和总结。 标题:“Handling Cookies is a Minefield”(处理Cookies是一场雷区) 假设性分析: 这篇文章可能探讨了在互联网上处理Cookies(网页上存储用户信息的片段)时遇到的挑战和潜在的问题。Cookies通常用于存储用户偏好、登录信息以及跟踪用户行为,但它们也可能被滥用,侵犯用户隐私,或导致安全问题。 以下是一个可能的总结: “在《处理Cookies是一场雷区》这篇文章中,作者深入探讨了在网站和应用程序中处理Cookies时可能遇到的复杂问题。Cookies作为实现个性化体验和简化用户登录过程的关键技术,虽然带来了便利,但也带来了隐私和安全风险。文章可能指出,不当使用Cookies可能导致用户数据泄露,甚至被用于恶意目的。为了解决这些问题,作者可能提出了以下几点建议: 1. 透明度:网站和应用程序应明确告知用户Cookies的使用目的和范围。 2. 控制权:用户应该有权选择是否接受Cookies,以及如何管理自己的Cookies。 3. 安全性:加强Cookies的安全性,防止未经授权的访问和篡改。 4. 遵守法规:遵循相关的数据保护法规,如欧盟的通用数据保护条例(GDPR)。 总之,文章强调了在处理Cookies时需要谨慎行事,以平衡用户体验和用户隐私保护。” 请注意,以上内容是基于标题的假设性分析和总结,实际内容可能与这个总结有所不同。要获取准确的信息,请直接访问提供的链接。
Post by: todsacerdoti
Comments:
maxwellg: Cookies are filled with weird gotchas and uncomfortable behavior that works 99.95% of the time. My favorite cookie minefield is cookie shadowing - if you set cookies with the same name but different key properties (domain, path, etc.) you can get multiple near-identical cookies set at once - with no ability for the backend or JS to tell which is which.<p>Try going to <a href="https://example.com/somepath" rel="nofollow">https://example.com/somepath</a> and entering the following into the browser console:<p><pre><code> document.cookie = "foo=a";
document.cookie = "foo=b; domain=.example.com";
document.cookie = "foo=c; path=/somepath";
document.cookie
</code></pre>
I get<p><pre><code> 'foo=c; foo=a; foo=b'</code></pre>maxwellg: Cookie中充满了奇怪的陷阱和不舒服的行为,99.95%的时间都有效。我最喜欢的cookie雷区是cookie阴影——如果你设置了同名但不同关键属性(域、路径等)的cookie,你可以一次设置多个几乎相同的cookie——后端或JS无法分辨哪个是哪个<p> 尝试转到<a href=“https:/;example.com/-somepath”rel=“nofollow”>https:"/;example.com;somepath</a>并在浏览器控制台中输入以下内容:<p><pre><code>document.cookie=“;foo=a“;;document.cookie=“;foo=b;domain=.example.com”;;document.cookie=“;foo=c;path=;“somepath”;;document.cookie</code></pre>我得到<p><pre><code>';foo=c;foo=a;foo=b</代码></pre>
kibwen: The article mentions Rust's approach, but note that (unlike the other mentioned languages) Rust doesn't ship any cookie handling facilities in the standard library, so it's actually looking at the behavior of the third-party "cookie" crate (which includes the option to percent-encode as Ruby does): <a href="https://docs.rs/cookie/0.18.1/cookie/" rel="nofollow">https://docs.rs/cookie/0.18.1/cookie/</a>
kibwen: 文章提到Rust;s方法,但请注意(与其他提到的语言不同)Rust不会;标准库中没有任何cookie处理设施,因此它;实际上,我们正在研究第三方的行为;饼干”;crate(其中包括像Ruby一样进行百分比编码的选项):<a href=“https:/;docs.rs/ cookie 0.18.1&#cookie";rel=“nofollow”>https:/;docs.rs;cookie;0.18.1;cookie</一
0xbadcafebee: Did anyone else notice that the HTTP protocol embeds within it ten-thousand different protocols? Browsers and web servers both "add-on" a ton of functionality, which all have specifications and de-facto specifications, and all of it is delivered through the umbrella of basically one generic "HTTP" protocol. You can't have the client specify what version of these ten-thousand non-specifications it is compatible with, and the server can't either. We can't upgrade the "specs" because none of the rest of the clients will understand, and there won't be backwards-compatibility. So we just have this morass of random shit that nobody can agree on and can't fix. And there is no planned obsolescence, so we have to carry forward whatever bad decisions we made in the past.
0xbadcafebee: 还有人注意到HTTP协议嵌入了一万种不同的协议吗?浏览器和网络服务器都是“;附加组件”;大量的功能,它们都有规范和事实上的规范,所有这些都是通过基本上一个通用的保护伞提供的";HTTP“;协议。您可以;不让客户端指定它与这一万个非规范兼容的版本,服务器可以;也不是。我们可以;t升级";规格”;因为其他客户都不会理解,所以他们赢了;不能向后兼容。所以我们只是有一堆随机的垃圾,没有人能达成一致,也没有人能;t修复。而且没有计划性的淘汰,所以我们必须继续执行过去做出的任何错误决定。
jeffreyrogers: About 10 years ago I implemented cookie based sessions for a project I was working on. I had a terrible time debugging why auth was working in Safari but not Chrome (or vice-versa, can't remember). Turned out that one of the browsers just wouldn't set cookies if they didn't have the right format, and I wasn't doing anything particularly weird, it was a difference of '-' vs '_' if I recall correctly.
jeffreyrogers: 大约10年前,我为一个正在进行的项目实现了基于cookie的会话。我花了很长时间调试为什么auth在Safari中工作,但在Chrome中不工作(反之亦然,我不记得了)。结果发现,其中一个浏览器不会;如果没有设置Cookie,则不会设置Cookie;我没有正确的格式,而且我是;没有做任何特别奇怪的事情,这是一个差异-';vs_';如果我没记错的话。
gweinberg: I got the impression that almost as soon as they were introduced people thought the only sensible use of cookies is to set an opaque token so the server can recognize the client when it sees it again, and store everything else server side.<p>I don;t understand why it's a problem that the client (in principle) can handle values that the server will never send. Just don't send them, and you don;t have to worry about perplexing riddles like "but what would happen if I did?"
gweinberg: 我得到的印象是,几乎在它们被引入后,人们就认为cookie的唯一合理用途是设置一个不透明的令牌,这样服务器在再次看到客户端时就可以识别它,并在服务器端存储其他所有内容<p> 我没有;不明白为什么;这是一个客户端(原则上)可以处理服务器永远不会发送的值的问题。只是不要;不要送他们,你也不送;不必担心诸如";但如果我这样做,会发生什么&“;