The defense that does work is to keep code and data in separate places. Then there is no way to compromise code by playing tricks with data. Garbage-collected languages like Perl and Lisp do this, and as a result are immune from buffer overflow attacks.
What. Am I slow today, or does that make zero sense?
On a slightly related note, Paul Graham's "Hacker News", a reddit-like site for hackers, uses a totally awesome approach to user sessions: every time you visit a page, a closure/continuation is created for every button that needs state (it is lisp, and lisp is all about closures and continuations, didn't you know), which is then run if you click it.
Now and then a garbage collector runs and removes stale closures, also they restart the server when it gets too slow.
Now you would think, that's sort of DoS-prone, those closures being fruitful and multiplying, but surely that only happens with pages shown to logged-in users, so they can ban abusers or something? Well, inspect source http://news.ycombinator.com/submit while not logged in (btw it's down again right now) reveals two of these closures created for every and each page view.
There's nothing stopping you from creating sessions for users who aren't logged in. Photobucket does it for sure.
Except for sanity. Are you sure they do it with server-side sessions, and not with cookies, like every other sane site out there?
I mean, all right, different strokes for different folks, but I would never associate a heavy as shit non-reified persistent activation record of a function with each of several buttons on a page that I show to everyone. That's a fun think to do for your pet rat's homepage, it's "elegant" (in a certain totally divorced from reality kind of way), but that's not how you do things with a public forum dedicated to sucking less at programming, as a community. In my humble opinion.
All I know for sure regarding photobucket is that if you visit it without a PHPSESSID cookie it seems to give you a fresh one.
I haven't really decided myself if using continuations in a web framework is a good idea or not for scalability reasons.
But doesn't storing the continuation just involve copying a portion of the stack? And since there's probably not a lot of state that needs to be saved, and a lot of things will be allocated on the heap anyway, they could use very little memory indeed.
I haven't really decided myself if using continuations in a web framework is a good idea or not for scalability reasons.
It's not like "it can never be done responsibly ever!", it's more like PG did not do it in anything resembling responsible manner. He was, like, oh, I can do a cute thing, I can write handlers for my buttons inline, and transparently store them as callbacks in a hash table and it will just work, and in a distinctly lispy way.
He stores more than one of them per page, as you can see in my screenshot, that's bad.
He stores them in an un-reified fashion, instead of considering what information he wants to store for a session and storing it explicitly in some serialized form, efficiently and fully aware of how much of it he stores, he relies on the underlying language machinery to implicitly keep track of the stuff, of the activation record of a handler and everything it might reference. So he doesn't know how much of it he actually stores per callback, how much of his memory is used by this stuff, and when there's too much of it everything slows to a crawl, that's bad. You want to compartmentalize and separate stuff like that from your actual application (isn't it ironic, considering the post that started this thread).
And that's not "little" memory at all, I would guess, given the general-purpose nature of the mechanism, that's bad, too.
He can't say, oh, sessions take too much space, how about I plug a second server with a shitton of memory and memcached and nothing else storing them, that's bad.
He probably could but doesn't say, well, let's associate one session with each logged-in user and try our best not to expire them, expiring anonymous sessions etc first. Instead he constantly creates these closures for everyone, then garbage collector deletes them at random apparently, so if you open some HN post, wait a couple of minutes, and try to comment, or take too long writing a comment, you're in for a surprise.
All in all it's one hell of a dangerous idea, which is implemented in the most reckless way possible.
69
u/the-fritz Mar 11 '13
That's the Lisp and 9/11 bit he's talking about in the beginning: http://www.paulgraham.com/hijack.html