News for hackers. Stuff that matters.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by minimaxir on Sunday October 14, 2012 @02:37PM (#4652137)
(I apologize in advance for linking to my own blog, but I had not seen this issue reported on any tech blog nor appeared in the "new" queue on HN, so I wrote a quick post this morning on the issue, as it's technically interesting.)
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by Negitivefrags on Sunday October 14, 2012 @03:39PM (#4652363)
> The proper way to implement a promo code is logical: when the user attempts to apply a promo code, the server checks, has the user used this promo code before? by querying SELECT FROM transactions WHERE user_id = current_user AND promo_code = “OS3874XVC”. If the result set is empty, then the user hasn’t used the code, and everything’s good to go.

Be very careful here, it's not as simple as it looks. If you don't do the correct locking it is very easy to have timing attacks which allow keys to be used twice.

We learned this the hard way after posting a one use key for our game on 4chan. A thousand people rushed to try the key and around 100 people managed to get in using it.

Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by numair on Sunday October 14, 2012 @04:06PM (#4652452)
... That's not a timing attack. A timing attack involves measuring the time taken to return an invalid response to a password attempt and, given enough tries, figure out the password based on this. It usually takes advantage of the way that string-matching code is written in libraries. Preventing this is not nearly as simple as you may think; for example, recent research shows that over a long enough period of time and enough attempts, it is possible for an attacker to factor network latency into their timing analysis.

What you're describing is not the result of an "attack," but rather the result of code that wasn't designed to deal with database locking. You weren't hacked, nobody attacked you; you just didn't design your system to deal with tons of people trying to write/read the same thing at the same time. Again, it's a tricky problem, so it's understandable (and a lot of people would consider dealing with such issues to be "premature optimization").

I will also note that the OP needs to stick to his MySQL Cookbook rather than commenting on coding practices for large-scale, heavy-usage web applications. His code suggestion is terribly naive, arrogant, and embarrassing. Yes, EA made a mistake; no, you have no clue what the hell you are talking about.

Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by mherdeg on Sunday October 14, 2012 @04:37PM (#4652567)
Yeah, time-of-check-to-time-of-use attacks are not usually described as "timing attacks" but instead just called TOCTTOU. In this scenario you might also say "exploiting a race condition".
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by trhtrsh on Monday October 15, 2012 @12:51AM (#4653825)
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by ams6110 on Sunday October 14, 2012 @03:48PM (#4652384)
It really isn't as easy as it sounds, is it? A better approach might be to UPDATE promo_codes SET used = 1 WHERE ... AND used = 0, and then check that one update occurred. Or if your db supports it, SELECT ... FOR UPDATE OF ... and then update if the code is not yet used. You want the check and the update to occur atomically. And this varies depending on databases, for example in Oracle even if you explicitly begin a transaction, a select does not lock the row (unless you specify FOR UPDATE OF) so if you do the check and the update in separate statements, you still have a race condition).
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by Negitivefrags on Sunday October 14, 2012 @04:24PM (#4652526)
I actually wasn't personally involved in the solution, but I believe that we went with something involving SELECT FOR UPDATE.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by nvmc on Sunday October 14, 2012 @03:59PM (#4652423)
Just out of interest, what is your game?
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by Negitivefrags on Sunday October 14, 2012 @04:22PM (#4652515)
Here is our site: http://www.pathofexile.com/
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by danneu on Sunday October 14, 2012 @07:13PM (#4652943)
My friend recently linked me to Path of Exile's expansive passive skill tree. Pretty inspiring to play around with that without even knowing anything about the game. I've pined for that kind of skill tree since I was a kid.

I recommend anyone to check it out: http://www.pathofexile.com/passive-skill-tree/. It looks like a star map.

Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by nvmc on Sunday October 14, 2012 @05:10PM (#4652659)
Ah, I bought a beta key a while ago. Nice to see local developers making a mark. Certainly the best hack/slash game out right now.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by cheald on Sunday October 14, 2012 @05:55PM (#4652778)
Thanks for a great game. PoE has made me a happy gamer.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by rcfox on Sunday October 14, 2012 @03:28PM (#4652336)
That's okay. You did a better job than what any of the popular tech blogs would have done.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by esrauch on Sunday October 14, 2012 @03:07PM (#4652265)
Sorry to comment off of the content of the post, but when I load the page the Like button flickers shown/not shown a bunch of times causing annoying visual jitter. I'm on Chrome 22 if that is relevant.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by minimaxir on Sunday October 14, 2012 @04:05PM (#4652445)
I figured out the error (I was wrong, it was indeed my code) and fixed it. No more flickering. :)
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by spicyj on Sunday October 14, 2012 @04:08PM (#4652465)
Out of curiosity, what was the bug?
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by minimaxir on Sunday October 14, 2012 @04:30PM (#4652550)
On my main page, I use AJAX to load the Share buttons when the user mouses-over the post itself, so that they aren't loaded all at once. Specifically, it loads the HTML, then runs it through each social service's HTML parser to render the buttons.

On individual blog posts, the buttons did not load because the DOM element is not present for that template. However, the parser still ran on mouse-over, which is what caused the flickering. So I just disabled the parser when the user is on an individual blog post.

Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by spicyj on Sunday October 14, 2012 @04:36PM (#4652564)
Gotcha. :)
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by minimaxir on Sunday October 14, 2012 @03:16PM (#4652294)
From what I can tell, that's on Facebook's end, as all the Facebook plugins seems to flicker occasionally as well. I'll look into it, although there's nothing unusual with my front-end code that should be causing unusual behavior...maybe CloudFlare caching issues?

Thanks for letting me know btw. :)

Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by gabemart on Sunday October 14, 2012 @03:19PM (#4652307)
Is there a problem with linking to your own blog?
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by mparlane on Sunday October 14, 2012 @03:36PM (#4652357)
Self promotion [of your own blog/site] is frowned upon I believe. We have SHOW HN: for when you want to show something off that you have done.

I think it's mainly to stop reporters at Gawker from linking to all their articles though ;)

Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by ars on Sunday October 14, 2012 @03:44PM (#4652378)
Self promotion is not frowned upon. As long as the content is good it doesn't matter who submits it.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by artursapek on Sunday October 14, 2012 @03:57PM (#4652413)
Right. People get their friends to link their blogs anyway, I see no difference in effect.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by bryanlarsen on Sunday October 14, 2012 @03:59PM (#4652425)
What is frowned upon is blogspam, rewriting somebody else's article and submitting your own version. Original content is always welcome.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by Evbn on Sunday October 14, 2012 @04:03PM (#4652436)
It doesn't stop. Jen at Betabeat's Reddit-Gawker gawking junk has been on the front page for days.
Re:EA “Gives Away” 1000s Of Free Games Due To No Server-Side... by NoPiece on Sunday October 14, 2012 @05:10PM (#4652657)
I don't think you have characterized the problem accurately (or at least completely). The coupon allowed you to add dozens of games to your cart, then applied the $20 off to each individual item instead of just one, or against the total. It was a logic problem in applying the coupon on the server side.