11 ms·
Handling cookies is a minefield
- deleted 2y ago[deleted]
- jerf 2y agoAnd the article isn't even about the proliferation of attributes cookies have, that browsers honor, and in some cases are just mandatory. I was trying to explain SameSite to a coworker, and scrolled down a bit... https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#cookie_prefixes https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#co... wait, cookie prefixes? What the heck are those? The draft appears to date to 2016, but I've been trying to write secure cookie code for longer than that, hadn't heard of it until recently, and I can't really find when they went in to browsers (because there's a lot more drafts than there are implemented drafts and the date doesn't mean much necessarily), replies explaining that welcome. Seems like every time I look at cookies they've grown a new wrinkle. They're just a nightmare to keep up with.
- minitech 2y ago> https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#cookie_prefixes https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#co... wait, cookie prefixes? What the heck are those? https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#cookie_prefixes https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#co... > For more information about cookie prefixes and the current state of browser support, see the Prefixes section of the Set-Cookie reference article. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#browser_compatibility https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Se... (Cookie prefixes have been widely supported since 2016 and more or less globally supported since 2019.) They’re backwards-compatible, so if your cookie need meets the requirements for the `__Host-` prefix, you should use `__Host-`.
- jerf 2y ago[flagged]
- minitech 2y agoI was answering your question about when they went into browsers with a link, and summarizing it in a parenthetical. So much for “replies explaining that welcome”, I guess.
- olddustytrail 2y agoIt's the first part of your reply they're responding to, where it looks like you've answered their rhetorical question with the exact link they used to illustrate it. I'd guess you just screwed up your copy paste and didn't notice.
- marcosdumay 2y agoWell, prefixes are opt-in. You don't have to keep-up with them. The only recent large problem with cookies were to changes to avoid CSRF, those were opt-out, but they were also extremely overdue. All of the web standards are always gaining new random features. You don't have to keep-up with most of them. They do look like bad abstractions, but maybe it's just the problem that is hard.
- paol 2y agoCookie header parsing is a shitshow. The "standards" don't represent what actually exists in the wild, each back-end server and/or library and/or framework accepts something different, and browsers do something else yet. If you are in complete control of front-end and back-end it's not a big problem, but as soon as you have to get different stuff to interoperate it gets very stupid very fast.
- hinkley 2y agoFirefox accepts five characters which RFC recommends that servers not send: 0x09 (horizontal tab) 0x20 (spaces) 0x22 (double quotes) 0x2C (commas) 0x5C (backslashes) I agree with at least some of these. Cookies without commas? Quotes?
- remram 2y agoQuotes in the value when quotes delimit the value? Yeah that seems dangerous to me.
- anamexis 2y agoQuotes don't delimit the value.
- pimlottc 2y agoPer the section 4.1.1 rules quoted in the article, cookie values can be optionally quoted: > cookie-value = cookie-octet / ( DQUOTE cookie-octet DQUOTE )
- anamexis 2y agoThat is true, but in that case they are part of the value itself, they're not doing anything special: > Per the grammar above, the cookie-value MAY be wrapped in DQUOTE characters. Note that in this case, the initial and trailing DQUOTE characters are not stripped. They are part of the cookie-value, and will be included in Cookie header fields sent to the server.
- kibwen 2y agoThe 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): https://docs.rs/cookie/0.18.1/cookie/ https://docs.rs/cookie/0.18.1/cookie/
- juped 2y agoDe facto standardization by snapping up good names early!
- echelon 2y agoNot really. A lot of essential third party Rust crates and projects have "weird" names, eg. "nom", "tokio", etc. You can see that from the list of most downloaded crates [1]. This one just happens to have been owned and maintained by core Rust folks and used in a lot of larger libraries. This is more the exception than the rule. It's a given that you should do due diligence on crates and not just use the first name that matches your use case. There's a lot of crate name squatting and abandonware. Rust crates need namespacing to avoid this and similar problems going forward. [1] https://crates.io/crates?sort=downloads https://crates.io/crates?sort=downloads
- dangsux 2y ago[dead]
- codetrotter 2y agoA sibling comment talked about “UwU names”. Not sure exactly if they are referring to “tokio” or something else. But if it’s tokio, they might find this informative: > I enjoyed visiting Tokio (Tokyo) the city and I liked the "io" suffix and how it plays w/ Mio as well. I don't know... naming is hard so I didn't spend too much time thinking about it. https://www.reddit.com/r/rust/comments/d3ld9z/comment/f03lnm8/ https://www.reddit.com/r/rust/comments/d3ld9z/comment/f03lnm... From the original release announcement of tokio on r/rust on Reddit. And also to the sibling commenter, if tokio is a problematic name to you: Would either of the following names be equally problematic or not? - Chicago. Code name for Windows 95, and also the name of a city in the USA. https://en.wikipedia.org/wiki/Development_of_Windows_95 https://en.wikipedia.org/wiki/Development_of_Windows_95 https://en.wikipedia.org/wiki/Chicago https://en.wikipedia.org/wiki/Chicago - Oslo. Name of a team working on OpenStack, and also appears in their package names. Oslo is the capital of Norway. https://wiki.openstack.org/wiki/Oslo https://wiki.openstack.org/wiki/Oslo https://en.wikipedia.org/wiki/Oslo https://en.wikipedia.org/wiki/Oslo If yes, why? If no, also why?
- AshleysBrain 2y agoCookies seem to be a big complicated mess, and meanwhile are almost impossible to change for backwards-compatibility reasons. Is this a case to create a new separate mechanism? For example a NewCookie mechanism could be specified instead, and redesigned from the ground-up to work consistently. It could have all the modern security measures built-in, a stricter specification, proper support for unicode, etc.
- cruffle_duffle 2y agoNeeds a better name than NewCookie though. Suggestions include SuperCookie, UltraCookie or BetterCookie Or to be slightly more serious avoid calling it a cookie and call it something else. Too much baggage surrounding the word cookie.
- layer8 2y agoTrickOrTreat would seem appropriate.
- jjkaczor 2y agoMuffin? Cake? You graduate from consuming cookies to eating...
- bell-cot 2y agoHis Majesty's English might suggest "biscuit".
- hehehheh 2y agoLimp Biscuit it is then.
- Dilettante_ 2y agoEveryone will surely be rushing to be the first one to disseminate this new technology!
- thaumasiotes 2y ago
- jeffrallen 2y agoThe article mocks Postel's law, but if the setter of the cookie had been conservative in what they sent, there would have been no need for the article...
- marcosdumay 2y agoThe problem with Postel's law is exactly that the sender is never conservative, and will tend to use any detail that most receivers accept.
- somat 2y agoSo the problem with Postel's law is that people don't follow Postel's law?
- marcosdumay 2y agoThe problem is that it's a prisoner's dilemma. And you can't cooperate on a prisoner's dilemma against the entire world.
- ndusart 2y agoSo, just be as conservative as possible when you produce data and as liberal as possible when you receive something. Your code will then require the least cooperation from *any* other code to be compatible with. Doing otherwise will require cooperation to adjust on the specificities clients expect, and you fall into the trap of the prisoner dilemna.
- marcosdumay 2y agoNo, when you create a protocol define exactly what you need what is optional and what is an error, and stick to that. Being liberal on what you accept is a path for disaster.
- 2y ago
- TheRealPomax 2y ago[comment intended for a different post, but too old to delete]
- recursive 2y agoNone of this explicitly has anything specifically to do with HTML.
- TheRealPomax 2y agoIt sure doesn't, that was a comment for a completely different post. I have no idea why HN posted this comment on this article instead of the PHP 8.4 article I thought I was commenting on O_o
- 0x073 2y agoIT IS a mess, but I never saw json inside a cookie. For json I use local storage or indexeddb.
- robgibbons 2y agoIn both cases (cookie vs localStorage) you're really just storing your data as a string value, not truly a JSON object, so whether you use a cookie or localStorage is more dependent on the use case. If you only ever need the stored data on the client, localStorage is your pick. If you need to pass it back to the server with each request, cookies.
- recursive 2y agoJSON is explicitly a string serialization format.
- robgibbons 2y agoRight, I meant it's not a JavaScript object. It's serialized into a string in any case, no matter which API you're stuffing it into. So it's a bit of a non-sequitur for the parent to suggest that it's somehow weird to store JSON in a cookie, but not in localStorage. It's all just strings.
- recursive 2y agoMy point is that there really is no such thing as "truly a JSON object".
- MBCook 2y agoI find it weird too. I’ve always considered cookies like very stupid key value stores. It would never occur to me to put something more than a simple token in a cookie. A username, and email address, some opaque thing. The idea of trying to use it for arbitrary strings just seems weird to my intuition, but I don’t really know why. Maybe just because when I was learning about them long ago I don’t remember seeing that in any of the examples.
- jmull 2y ago> minefield Cookies are a bit of a mess, but if you're going to use them, you can follow the standard and all will be well. Not so much a minefield, but a hammer; you just need to take some care not to hit yourself on the thumb. I guess the confusion here is that the browser is taking on the role of the server in setting the cookie value. In doing so it should follow the same rules any server should in setting a cookie value, which don't generally allow for raw JSON (no double-quote! no comma!). Either use a decent higher-level API for something like this (which will take care of any necessary encoding/escaping), or learn exactly what low-level encoding/escaping is needed. Pretty much the same thing you face in nearly anything to do with information communication.
- klysm 2y agoI don’t understand how that’s not a minefield, it’s easy to go astray?
- johnisgood 2y agoProbably just semantics.
- jmull 2y agoWell, we’re getting into how to choose metaphors here. Not being literal, there’s always room to stretch. Still, you try to choose a metaphor with characteristics congruent with the topic. With a minefield, you can be doing something perfectly reasonable, with eyes open and even paying attention yet nevertheless it can blow up on you. Here, though, there’s no special peril. If you just follow the standard everything will be fine. If this is a minefield, then practically everything in software development is equally a minefield and the metaphor loses its power. (Later in the article they touch on something that is a minefield — updating dependencies. There’s probably a good article about that to be written.)
- deleted 2y ago[deleted]
- rendall 2y ago[flagged]
- AlienRobot 2y ago>everything behaves differently, and it's a miracle that [it] work at all. The web in a nutshell.
- mdaniel 2y agoBrowsers: what it would look like if Postel's Law were somehow made manifest in C++ and also essential to modern life
- ralmidani 2y agoWait til you have a legacy system and a newer system and need to, among other things: - Implement redirects from the old login screen to the new one - Keep sessions in sync - Make sure all internal and external users know how to clear cookies - Remind everyone to update bookmarks on all devices - Troubleshoot edge cases
- jeffreyrogers 2y agoAbout 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.
- deleted 2y ago[deleted]
- hombre_fatal 2y agoIIRC there is (or was?) a difference in case-sensitivity between Safari and Chrome, maybe with the Set-Cookie header? I've run into something before which stopped me from using camelCase as cookie keys. Can't seem to find the exact issue from googling it.
- nghia999 2y ago[flagged]
- hinkley 2y agoOne of the things I’ve always found frustrating about cookies is that you have to do your own encoding instead of the API doing it for you. I’m sure someone somewhere does but too often I’m doing my own urlencode calls.
- mdaniel 2y agoEncoding is at least solvable, but every browser having their own cookie length versus some standard value makes that some nonsense. Kong actually has a plugin to split (and, of course, recombine) cookies just to work around this
- hinkley 2y agoBut it's so solvable that I shouldn't have to solve it
- 0xbadcafebee 2y agoDid 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.
- tyleo 2y agoTbh I’ve made peace with this world and I might even enjoy it more than the planned obsolescence one.
- eru 2y agoThat was the model that Microsoft used at the height of their power and dominance in the 1990s and 2000s.
- Analemma_ 2y agoThis is also the fault of shit-tastic middleware boxes which block any protocol they don't understand-- because, hey, it's "more secure" to default-fail, right?-- so every new type of application traffic until the end of time has to be tunneled over HTTP if it wants to work over the real Internet.
- deleted 2y ago[deleted]
- dumpsterdiver 2y ago> middleware boxes which block any protocol they don't understand-- because, hey, it's "more secure" to default-fail, right? If the intent is to secure something then failing-open will indeed be at odds with that goal. I suspect you’re not implying otherwise, but rather expressing frustration that such providers simply can’t be bothered to put in the work and use security as an excuse.
- joshstrange 2y ago> Apple Support Are we sure the website wasn't just broken normally? I kid, a bit, but good lord does Apple _suck_ at websites. Apple Developer and, more often, App Store Connect is broken for no good reason with zero or a confusing error message. Note: I'm typing this on a M3 Max MBP (via a Magic Keyboard and Magic Mouse) with an iPhone 16 Pro and iPad Mini (N-1 version) on the desk next to me with an Apple Watch Series 10 on my wrist and AirPods Pro in my pocket. I'm a huge Apple fanboy, but their websites are hot garbage.
- mdaniel 2y agoBut why wouldn't web pages written in ObjC be just awesome and easy to manage?! https://en.wikipedia.org/wiki/WebObjects https://en.wikipedia.org/wiki/WebObjects I can still remember when they'd purposefully take down their store page for some godforsaken reason. The mind reels
- russelg 2y agoThey still do take the store page offline in the leading hours and during a keynote.
- karaterobot 2y ago> Handling cookies is a minefield I know! You gotta let them cool down first. Learned this the hard way.
- dekhn 2y agoEverything about the web is a minefield. It's an exercise in "how many unnecessary layers can we put between users and their content"?
- whatever1 2y agoI have a solution! I just made one more framework!
- flockonus 2y agoWhat are you implicitly comparing it against?
- dekhn 2y agoNative desktop development.
- tobyhinloopen 2y agoElectron: Eyes Emoji
- bvrmn 2y agoAka unindexable, unsearchable, violation access error mess.
- dekhn 2y agoIndexing doesn't really work well if cookies are involved. And if indexing doesn't work, then searching doesn't. Web pages fail for me (javascript or whatever) far more often then I get a "violation access error" from my desktop programs.
- bvrmn 2y agoGood luck to have HN as a native app and get a huge diverse community around :P
- deathanatos 2y agoThat is a bit of a minefield, I agree… The way around this, as a developer, is URL-safe-base64 encode the value. Then you have a bytes primitive & you can use whatever inner representation your heart desires. But the article does also note that you're not 100% in control, either. (Nor should you be, it is a user agent, after all.) I do wish more UAs opted for "obey the standard" over "bytes and an prayer on the wire". Those 400 responses in the screenshots … they're a conforming response. This would have been better if headers had been either UTF-8 from the start (but there are causality problems with that) or ASCII and then permitted to be UTF-8 later (but that could still cause issues since you're making values that were illegal, legal).
- johnp_ 2y ago> URL-safe-base64 And make sure to specify what exactly you mean by that. base64url-encoding is incompatible with base64+urlencoding in ~3% of cases, which is easily missed during development, but will surely happen in production.
- Retr0id 2y agoIsn't it a lot more than 3%? I don't think I've heard anyone say url-safe-base64 and actually mean urlencode(base64(x))
- deathanatos 2y ago… yeah. I assume they're getting that from doing 3/64, but for uniform bytes, you're rolling that 3/64 chance every base64-output-character. (And bytes are hardly uniform, either … TFA's example input of JSON is going to skew towards that format's character set.)
- deathanatos 2y agooh, geez. No, just base64, using the URL safe alphabet. (The obvious 62 characters, and "-_" for the last two. It's called "urlsafe base64", or some variant, in the languages I work in. > This encoding may be referred to as "base64url". https://datatracker.ietf.org/doc/html/rfc4648#section-5 https://datatracker.ietf.org/doc/html/rfc4648#section-5 But yeah, it's not base64 followed by a urlencode. It's "just" base64-with-a-different-alphabet.
- khana 2y ago[dead]
- maxwellg 2y agoCookies 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. Try going to https://example.com/somepath https://example.com/somepath and entering the following into the browser console: document.cookie = "foo=a"; document.cookie = "foo=b; domain=.example.com"; document.cookie = "foo=c; path=/somepath"; document.cookie I get 'foo=c; foo=a; foo=b'
- draw_down 2y agoYeah, isn’t that how you represent a list of values? (Or maybe better to say a collection, not sure if ordering is preserved)
- kevincox 2y agoBut if the attributes are exactly the same then the cookies replace each other. So this isn't a general mechanism for representing a list. Not to mention that the way to delete a cookie is sending a replacement cookie that expires in the past. How are you supposed to delete the right cookie here?
- sieabahlpark 2y ago[dead]
- HappMacDonald 2y agoIs there a way for JS to see the attributes for each value? Because presumably setting an expire time in the past and iterating over every used set of attributes would get the job done to delete the cookie. Iterating over all possible (plausible?) attributes may also work, but knowing the specific attributes set would narrow that list of erasing writes to issue.
- 2y ago
- trevor-e 2y agoI came across a similar issue when experimenting with the Crystal language. I thought it would be fun to build a simple web scraper to test it out, only to find the default HTTP client fails to parse many cookies set by the response and aborts.
- burntcaramel 2y agoRe Safari’s networking code being closed source, a good substitute might be the Swift port of Foundation. You can see checks for control and delete characters here: https://github.com/swiftlang/swift-corelibs-foundation/blob/c28bf23e18e217709dddd5c2c1b3ee1f2a4151cb/Sources/FoundationNetworking/HTTPCookie.swift#L790 https://github.com/swiftlang/swift-corelibs-foundation/blob/...
- gweinberg 2y agoI 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. 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?"
- mu53 2y agoCookies are an antiquated technology. One of the first introduced while the web was still young in the 90s, and they have had a few iterations of bad ideas. They are the only place to store opaque tokens, so you gotta use them for auth.
- vbezhenar 2y agoThey are not the only place to store tokens. You can store tokens with localStorage for JS-heavy website, in fact plenty of websites do that. It's not as secure, but acceptable. Another alternative is to "store" token in URL, it was widely used in Java for some reason (jsessionid parameter).
- lknuth 2y agoTo expand on the "not as secure" comment: local storage is accessible to every JS that runs in the context of the page. This includes anything loaded into the page via <script src=""/> like tracking or cookie consent services.
- brabel 2y agoAnd I feel like it's important to expand on the fact that Cookies are visible to JS by default as well, except if the Cookie has the `HttpOnly` attribute set. Obviously, for auth, you absolutely want the session cookie to have both the `Secure` and `HttpOnly` attributes. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#block_access_to_your_cookies https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#bl...
- IgorPartola 2y agoCookies need to die. Their only legitimate use is with for which we have the Authentication header. Having a standard way to authenticate into a website in a browser would be amazing, just too bad that Basic and Digest auth wasn’t good enough at the time. As a bonus we could get Persona-style passwordless future.
- wdr1 2y agoWhy are first-party cookies bad?
- IgorPartola 2y agoThey are not bad they just are unnecessary. If your application uses local state, use local storage. If you store session data on the server, identify the user using the Authorization header. Why send arbitrary strings back and forth often with requests that don’t need them. Plus the technology is clearly rotten. They never got namespacing snd expiration right so you can just do weird stuff with them. Also, CSRF wouldn’t be a thing if cookies weren’t. This is like saying “why is finger/gopher/etc. bad?” They are not exactly bad but they are obsolete.
- baggy_trough 2y agoHow would you use the Authorization header to implement server side session data?
- seandoe 2y agoI think they mean storing an identifier in local or session storage and then sending it in the header.
- baggy_trough 2y agoIt doesn't work with basic multi page sites though.
- tigerlily 2y agoThat reminds me of the Frog and Toad story about willpower vs eating cookies. Yes, handling cookies is a mine field! I read the collected stories with my two year old, though I made sure we skipped the scary ones with the Dark Frog. I think the cookies ending was a little over his head, but we had fun taking turns acting out Toad pulling his blankets over his head when Frog tells him it's spring.
- matsemann 2y agoGo and failing to parse http headers correctly should become a meme at some point. One issue we had was the reverse proxy inserting headers about the origin of the request to the server behind. Like ip, ip city lookup etc. And that parsed through a service written in go that just crashed whenever the city had a Norwegians letter in it, took ages to understand why some of our (luckily only internal) services didn't work for coworkers working from Røros for instance. And that was again not the fault of the Go software, but how the stdlib handled it.
- bvrmn 2y agoAlmost nobody uses SimpleCookie.load for python. Flask, FastAPI, Django have own more relaxed parsers which doesn't break on invalid byte.
- NegativeLatency 2y agoThere’s a nasty bug in the python cookie parser, cookies after a cookie with quotes will be dropped: https://github.com/python/cpython/pull/113663 https://github.com/python/cpython/pull/113663 Zoom or some other website our customers use was writing a cookie with quotes that would break the site. Amazingly hard to reproduce and debug.
- replacecookies 2y agoI got a trick. Just dont make them, and dont accept them.
- indulona 2y agoLiterally everything in IT runs on decades old principles and technologies. The world simply refuses to fix things because "if ain't broken, don't fix it" philosophy. Look at TCP, HTML, JSON, SMTP..all good tech but insanely old and outdated and overtaxed for that it was invented for. When people joke that the entire banking industry runs on excel sheets, they are really not far from truth. Things will be shitty until they completely break down and people are forced to fix them. Look at JavaScript, this horribly stinking steaming pile of green diarrhea that rules over the entire front-end is still being worked on and developed and billions of money and countless work-hours have been wasted in order to make it somewhat usable, instead of just coming up with entirely new tech suitable for the 21st century. This is the entire internet and tech in general.
- deleted 2y ago[deleted]
- burnt-resistor 2y agoNeed to alternate background color-code (61e272 / e26161 + 63b754 / b75454) tables because reading a sea of Yes and No requires too much effort.
- jmull 2y ago> ...tragedy of following Postel's Law. The "law" is: "Be liberal in what you accept, and conservative in what you send." But here the problem is caused by being liberal in what is sent while being more conservative in what is accepted. It's using invalid characters in the cookie value, which not everything can handle. Following Postel's law would have avoided the problem.
- rcxdude 2y agoPostel's law is the main reason why there are so many cases where something is being liberal in what it sends. It's a natural approach when trying to enter into an existing ecosystem, but when the whole ecosystem follows it you get a gigantic ball of slightly different interpretations if the protocol, because something that is non-compliant but happens to work with some portion of the ecosystem won't get discovered until it's already prevalent enough it now needs to be accounted for by everyone, complexifying the 'real' spec and increasing the likelihood someone else messes up what they send.
- jmull 2y agoI don't think you can blame postel's law for people not following it. > when the whole ecosystem follows it you get a gigantic ball of slightly different interpretations You're describing the properties of a long-lived, well-used, well-supported, living system. We'd all like the ecosystems we have to interact with to be consistent and well-defined. But even more importantly, we'd like them to exist in the first place. Postel's law lets that happen. If your app is a leaf node in the ecosystem, and it's simple enough that you have direct control over all the parts of your app (such that you can develop, test, and release updates to them on a unified plan/timeline), then, yes, fail-early pickiness helps, because the failures happen in development. Outside of that you end up with a brittle system where the first place you see many failures is in production.
- rcxdude 2y agoI think you can blame Postel's law for being self-defeating. If the whole ecosystem is conservative in what it accepts, the whole ecosystem will be conservative in what it sends (because otherwise it won't be part of it). If the whole ecosystem is liberal in what it accepts (or just a significant part of it), some parts of it will be liberal in what it sends (because not everyone is going to rigidly follow the spec once they get something working well enough for the parts they test with), and that's where the problem comes from.
- arkh 2y ago> Many languages, such as PHP, don't have native functions for parsing cookies, which makes it somewhat difficult to definitively say what it allows and does not allow. What? Parse a cookie with http://php.adamharvey.name/manual/en/function.http-parse-cookie.php http://php.adamharvey.name/manual/en/function.http-parse-coo... Send a cookie with https://www.php.net/manual/en/function.setcookie.php https://www.php.net/manual/en/function.setcookie.php or https://www.php.net/manual/en/function.setrawcookie.php https://www.php.net/manual/en/function.setrawcookie.php Or if you have to check how php populates the $_COOKIE superglobal I think it is somewhere is this file: https://github.com/php/php-src/blob/master/main/php_variables.c https://github.com/php/php-src/blob/master/main/php_variable...
- solatic 2y agoAuthor started with throwing the results of JSON.stringify into a cookie, and I was surprised that his issue wasn't just that someone had thrown a semicolon into the JSON that was being stringified. Most of the headaches around cookies seem to be around people trying to get them to work with arbitrary user input. Don't do that. Stick with fixed-length alphanumeric ASCII strings (the kind you use for auth tokens) and you'll be fine.