6 ms·
It seems to me like the underlying issue was ignoring HTTP semantics and making a state-changing link like a logout link a plain <a> (HTTP GET) and not somethin
by jof 2y ago
It seems to me like the underlying issue was ignoring HTTP semantics and making a state-changing link like a logout link a plain <a> (HTTP GET) and not something like a form submission (HTTP POST).
Having intuition for the foundational layers of our tools saves so much time and future headaches.
- graypegg 2y agoTo be fair, <a> tags can't send out non-GET requests. Which yes, can be interpreted as "logout controls should be buttons in forms, not links", but I would really like native htmx-like attributes for intractable html elements.
- Ethee 2y agoGenuine question: How do you believe one should learn these semantics? This is more something I've been pondering myself recently, because I agree with you that the foundational knowledge for our work in any tech stack is usually the most important for understanding higher abstractions. But with so much to know it feels impossible to 'know it all' so to speak especially if you wear more than one specialized hat. Then beyond that even if you're only trying to learn just the foundations how do you know what those foundations are if you're not already inundated in that stack? This is mostly just my personal ramblings, but I'd be curious other peoples viewpoints on this.
- ori_b 2y agoThe RFCs are often fairly well written and not so hard to digest.
- pixl97 2y agoWhile it may not be quite the same answer you're looking for, I'd suggest the OWASP, and at least their top 10 for sure. Learning about SSRF may not have stopped this behavior (it's coming from the authenticated browser), but if you're doing CSRF checks you won't get logged out by random links on other peoples sites, and that whatever logged you out was a legitimate action.
- codetrotter 2y agoI remember many years ago when I used to read print magazines about programming and web development. One of those magazines told a story about a web site that had lost a lot of data. What had happened? Well, somehow they had this page that 1. Required no authentication at all, and 2. Was using links like <a href="/path/to/file?action=delete>Delete file</a> And so the Google web crawler had come across this page and happily visited each and every one of those links. That’s when I learned about the importance of using forms with POST requests for certain actions instead of using links that send GET requests. And then some years later someone told me about this thing called HATEOAS and about RESTful APIs and that actually there are different HTTP verbs you can use other than just GET and POST. Like for example DELETE /path/to/file As for your question about how someone is supposed to learn that these days? Ideally whatever web development tutorials or courses or books they are using would at some point tell them about the different HTTP verbs that exists, and of how and when to use each of them, and crucially to tell them about bad consequences of using GET for anything that has side-effects like logging out a session or deleting a file.
- 2OEH8eoCRo0 2y agoIt requires slowing down. Unheard of.
- morning-coffee 2y agoExactly. And ditching the "move fast and break things" mindset. Learn your craft and embrace the learning process. Always be curious about how the stuff below your layer works, fundamentally. Recurse on searching for the seminal works that defined those layers. This seems appropriately relevant today: https://news.ycombinator.com/item?id=41208627 https://news.ycombinator.com/item?id=41208627 We (the industry) have built up so many layers upon layers and frameworks designed to make things easier that it just seems to attract newcomers to software engineering with this mindset that all it takes is to start with the sample-app for a high level framework, hack on it with trial and error until it does something they want, and then take to social media with proclamations of "Look! I built a thing! You can hire me to build your thing now!"
- recursivedoubts 2y agoThis is a very good example where the HTML extensions that alex proposed here: https://www.youtube.com/watch?v=inRB6ull5WQ https://www.youtube.com/watch?v=inRB6ull5WQ (TLDW: allow buttons to make HTTP requests; allow buttons & forms to issue PUT, PATCH & DELETE; allow buttons, forms & links to target elements in the DOM by id instead of only iframes) would improve the web platform. You could have a stand-alone logout button that issues a DELETE to /session or whatever. Nice and clean.
- williamdclt 2y agoI mean, it should just be a submit for a form with a /logout POST action. It’s standard and what web devs have been doing for decades
- recursivedoubts 2y agoYeah, the problem is that it requires a form, which has layout implications w/o styling and POST is not idempotent, whereas a logout operation typically is idempotent. Being able to issue a DELETE to a URL like /session from an element that doesn't have layout implications would be ideal.
- de46le 2y agoA button doesn't have to be inside a form, though. You could have an empty form as a neighbour to the button (or anywhere else inside the page body), and associate the button with it. <button form="logout-form" ...>logout</button> <form name="logout-form"></form> No layout implications that way, barring any nth-child css (solvable by putting the form somewhere else). Doesn't solve the form being limited to GET/POST, but styling concerns are atleast handled.
- recursivedoubts 2y agodoable but rarely used, inconvenient and awkward, alex proposes allowing buttons to be stand-alone hypermedia controls which also allows multiple buttons located within a form to perform different actions (e.g. save v. cancel)
- togakangaroo 2y agoAuthor of the post here, There was no form submission, I'm not sure where you got that. There was also no POST. Though yes, I agree that in the core HTTP semantic, you wouldn't want to change state on a GET and that should include not calling `Set-Cookie`. And yet the reality is that that nearly every application - and many popular libraries like auth0 - do in fact set and clear cookies on `GET`. The issue here was that the `Link` component in NextJs - does preloading by default (which is a bad idea exactly for the above reason of reality being different from theory) - doesn't do preloading by default when running on the dev server (so you don't see the error until its deployed) - because it does preloading directly in javascript, it can't possibly follow the HTTP semantic of not actually applying cookies until later when the cached route is used Everything else was the wild goose chase bits. Also I asked claude to criticize the article as a web forum might before publishing, and this is definitely the tone it gave :D Oh, also, I'm pretty sure I got the part wrong where i was talking about the preload attribute in HTML, but so far no one's noticed. I should correct that.
- thedanbob 2y ago> There was no form submission, I'm not sure where you got that. There was also no POST. OP was saying the logout function should have been behind a form submission / POST.
- togakangaroo 2y agoAh, yes, I mean, agree that would have been technically correct, but like I said, its just not how a lot of the web works. auth0-nextjs seems to react to `GET` by default (though it might also work with `POST` and you certainly can override things)
- soneca 2y agoSo OP was correct that a proper use of the foundational layer of HTTP would have saved time, yours in particular, right? Also, I didn’t get your ”Claude predicted your tone smiley” thing. OP tone seemed polite and clear. Your tone, on the other hand, seemed defensive and dismissive. Even after you realizing that you initially misunderstood what OP said, adding a “I mean” and a “but I like I said” to reinforce you were right even while misreading what OP said (rather than just acknowledging you got it wrong in the first reading). I would go even further and speculate that you were predisposed to get a dismissive tone from a web forum (your previous Claude test suggests that) so much that you got a perfectly fine comment and misread in a way that it felt in the “wrong tone” to you. Even misunderstanding what the post said. All of that to confirm your predisposition.