News for hackers. Stuff that matters.
Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @01:42AM (#519462)
Yes. I made an unbelievably stupid mistake in the code that generates forms with labelled fields. It was basically functional programming taken a little too far: I generated the same form whether the fields were editable or not, and then later if there were no editable fields I just omitted the submit button. So anyone looking at the source of one of these pages could find a fnid that would work to modify the object displayed on it. (There's still a fnid, but it no longer does anything.)
Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @02:32AM (#519521)
Actually on closer examination the bug was subtler than that. I did check whether the incoming request was allowed to modify each field it was trying to modify. But the code that decided whether a field was modifiable was using a four variable list to destructure on a five value description of the field. This caused the variable determining whether a field was modifiable to be bound instead to the value saying whether or not it should be displayed. Which meant every field that was displayed was modifiable.
Re:Ask HN: Has Hacker News been hacked/cracked? by IHackedHN on Tuesday March 17, 2009 @02:42AM (#519529)
That's actually pretty interesting to me. I didn't notice that when I was looking at the Hacker News code. Perhaps Arc shouldn't allow a list to be destructured except with a list of the same length? Allowing differing lengths seems likely to cause subtle bugs like this.
Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @02:59AM (#519546)
I generally tried to err on the side of flexibility, and it seemed more flexible not to require the lengths to match. I could imagine cases where you might want to use patterns both longer and shorter than the lists they were matched against. On the other hand, I'm not sure I've ever ended up taking advantage of this.
Re:Ask HN: Has Hacker News been hacked/cracked? by IHackedHN on Tuesday March 17, 2009 @03:15AM (#519558)
Maybe you could use something along the lines of &rest to optionally support a pattern shorter than the matched list?
Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @03:18AM (#519562)
You could do that with a dot now. The trouble is, you end up creating a junk variable:

    arc> (let (x . y) '(a b c) y)
    (b c)
Re:Ask HN: Has Hacker News been hacked/cracked? by IHackedHN on Tuesday March 17, 2009 @03:34AM (#519573)
Making users create junk variables seems to me like better behavior than the current implicit behavior. It's your decision, though, of course.

Anyway, is it safe to assume that you're not going to try to get me arrested or anything?

Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @04:08AM (#519597)
I feel like unnecessary variables are extra bad; in cognitive terms they feel like they add more than one token to the length of a program.

Do you mean your username is actually descriptive? Since you are obviously a Lisp hacker, I'd be happy to have a truce. Can you send me an email?

Re:Ask HN: Has Hacker News been hacked/cracked? by IHackedHN on Tuesday March 17, 2009 @04:34AM (#519612)
Thank you. I've sent you an email.
Re:Ask HN: Has Hacker News been hacked/cracked? by wingo on Tuesday March 17, 2009 @05:22AM (#519638)
You don't have to name it. It could be _.

    (let (x . _) '(a b c) x)
It sounds like you're treating list destructuring like CL's mvbind. While it's subjective of course, I'm more comfortable with the runtime doing what I mean when I control the number of values (modulo `(apply values ...)').

I'm not comfortable with destructuring values "flexibly" when I don't control the data coming in.

Re:Ask HN: Has Hacker News been hacked/cracked? by parenthesis on Tuesday March 17, 2009 @11:45AM (#520000)
Except "_" is a perfectly good name for a symbol in Arc.

"nil" could be used instead, since nil isn't allowed to be rebound.

  (let (x . nil) '(a b c) x)
even works already, since (unless it's been changed in some newer version of Arc I haven't installed yet) Arc just silently ignores the let-ing of nil:

  (let nil t nil) ---> nil
Re:Ask HN: Has Hacker News been hacked/cracked? by simonb on Tuesday March 17, 2009 @04:10AM (#519599)
But at the same time this junk variable is code-as-documentation professing the incomplete destructuring is intentional.

You could go a step further and have a special ignore symbol, (for instance * ) like most pattern matching languages/libraries have with the property that it can appear multiple times:

  arc> (let (x * y . *) '(a b c d e f) y)
  c
Re:Ask HN: Has Hacker News been hacked/cracked? by dfranke on Tuesday March 17, 2009 @02:52AM (#519535)
For a language of my own design I'd agree, but I think that would be rather severely contrary to the spirit of Arc.
Re:Ask HN: Has Hacker News been hacked/cracked? by jganetsk on Tuesday March 17, 2009 @10:16AM (#519874)
For all people who say good programmers don't make type errors, here's a counterexample.
Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @08:10PM (#520867)
It's an interesting question whether it's really a type error to mismatch the sizes of things. I feel like sometimes it is and sometimes it isn't.
Re:Ask HN: Has Hacker News been hacked/cracked? by KayEss on Wednesday March 18, 2009 @01:30AM (#521252)
In a strongly typed language one would normally want to reify the number in the type system whenever possible, i.e. the use of (a,b,c,d,e) rather than [a,b,c,d,e] in Haskell (that's a 5-tuple rather than a 5 element list).

I think that people used to dynamic programming languages would normally pick the list rather than the tuple simply because it at first appears easier. I think Dijkstra had something to say on that particular subject :)

Re:Ask HN: Has Hacker News been hacked/cracked? by jganetsk on Wednesday March 18, 2009 @12:18AM (#521178)
Agreed. But it sounded like, in this case, you were using a list to represent that which would have been represented by a record in a statically typed language.

I'm imagining you'd have some kind of Field record type, with isDisplayable and isModifyable fields. Instead of destructuring as a list (or tuple), you would explicitly look for isDisplayable and isModifyable.

But, of course, you could still make the same mistake in a statically typed language if you chose not to set up the data structure this way.

Re:Ask HN: Has Hacker News been hacked/cracked? by IHackedHN on Tuesday March 17, 2009 @01:58AM (#519489)
You fixed the hole with impressive speed. I've got to give you that.

Out of curiosity, why did you take the site down two times before applying the fix?

Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @03:02AM (#519548)
The first time Trevor restarted it a few seconds before the fixed code actually arrived on the server.
Re:Ask HN: Has Hacker News been hacked/cracked? by unalone on Tuesday March 17, 2009 @01:48AM (#519469)
That would suggest, then, that the comment points and submission points are also controllable within some form, since they were tampered with also. Is that the case? (I'm not asking because I don't believe you - I'm just wondering how those numeric fields were altered.)
Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @01:52AM (#519478)
Any field of any object could be changed this way.
Re:Ask HN: Has Hacker News been hacked/cracked? by suhail on Tuesday March 17, 2009 @01:49AM (#519473)
Almost sounds like SQL Injection, perhaps no escaping on fnid?
Re:Ask HN: Has Hacker News been hacked/cracked? by markbao on Tuesday March 17, 2009 @01:51AM (#519477)
Edit: I'm wrong, see below.

If I'm not mistaken, that had nothing to do with SQL injection. The fnid basically was the authenticator that allowed a person to edit a page, regardless of who was logged in.

What about other HN-powered Arc sites? Are they vulnerable as well? I won't name names, because I'm guessing they are indeed vulnerable.

Edit: Yes, they are.

Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @01:52AM (#519479)
Not quite. A fnid is a hash key pointing to a closure on the server.
Re:Ask HN: Has Hacker News been hacked/cracked? by markbao on Tuesday March 17, 2009 @01:56AM (#519486)
Ah, okay. Wrong guess. Everyone can downvote me now :)
Re:Ask HN: Has Hacker News been hacked/cracked? by ralph on Tuesday March 17, 2009 @08:00AM (#519749)
With hindsight, do you still feel fnids are a good way to go? They present an obvious bottleneck in that the server has to remember many closures for a period of time as opposed to having each client remember their share. I know you drastically reduced the use of fnids some time ago. I wonder if the remainder are a vestige that's OK to live with because life's too short, or there's fundamentally a strong argument for them I'm missing.
Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @12:37PM (#520089)
Sometimes these closures have more stuff in them than you could conveniently put in a url. For example, they might refer to another closure describing what to do next. When you try to do something that requires you to be logged in, for example, you're given the login page, with a fnid referring to a closure describing what you were in the middle of doing. That's why after logging in you're able to continue doing whatever you were doing.
Re:Ask HN: Has Hacker News been hacked/cracked? by dha on Tuesday March 17, 2009 @09:45PM (#520981)
Agreed. How about making the fnid a signed cache of often used environment variables(instead of a random string), which could also be looked up via a more time consuming method if needed. Depends really on your traffic profile how much data could reasonably and cost-effectively be cached, but it could be a very sizable portion saved by retrofitting the current method.
Re:Ask HN: Has Hacker News been hacked/cracked? by wlievens on Tuesday March 17, 2009 @04:35AM (#519613)
Indeed. fnid = function id
Re:Ask HN: Has Hacker News been hacked/cracked? by ambition on Tuesday March 17, 2009 @01:32PM (#520181)
I think I've found and fixed for hnacademic.com, thanks to the wonderful details here.
Re:Ask HN: Has Hacker News been hacked/cracked? by tptacek on Tuesday March 17, 2009 @08:13AM (#519757)
It's very much like the "mass assignment" bugs that hit Rails servers when people forget to limit the writeability of Active Record attributes.
Re:Ask HN: Has Hacker News been hacked/cracked? by brlewis on Tuesday March 17, 2009 @10:32AM (#519891)
Escaping is needed when you pass strings to a program that parses and interprets them. That's not part of HN's architecture AFAICT. There shouldn't be any opportunity to introduce a vulnerability similar to SQL injection.
Re:Ask HN: Has Hacker News been hacked/cracked? by inerte on Tuesday March 17, 2009 @02:01AM (#519493)
And are the YC application forms secure(d)?...
Re:Ask HN: Has Hacker News been hacked/cracked? by pg on Tuesday March 17, 2009 @02:25AM (#519512)
Against this bug at least, yes.
Re:Ask HN: Has Hacker News been hacked/cracked? by pelle on Tuesday March 17, 2009 @01:59AM (#519490)
I'm glad no major damage happened.

Anyway your mention of fnid prompted me to learn a bit about arc and the arc web server which looks very interesting. Might have to play with it a bit.

http://arcist.com/doc/srv.html