News for hackers. Stuff that matters.
Re:Hide this in your coworkers' JavaScript code tomorrow by madeofpalk on Monday March 31, 2014 @08:49AM (#7501055)
On a related note, I got a pleasent surprise when I opened the Developer Console on Facebook.com: they present you with a giant red warningp[1] and block any code execution in it until you explicitly 'allow [your] account to be hijacked if I paste malicious Javascript'[2]

[1]: http://i.imgur.com/6UVaTen.png

[2]: https://www.facebook.com/selfxss

Re:Hide this in your coworkers' JavaScript code tomorrow by hashx on Monday March 31, 2014 @08:54AM (#7501082)
Facebook blocks the console as it is supposedly used for " exploitation by people to post spam and even used to "hack" accounts"

http://stackoverflow.com/questions/21692646/how-does-faceboo...

Re:Hide this in your coworkers' JavaScript code tomorrow by danielweber on Monday March 31, 2014 @09:51AM (#7501417)
When you consider Facebook's target audience, it's probably okay to make people like us jump through a hoop in order to stop Grandma from being completely p0wned by typing in some JavaScript.

Yes, maybe people should know that running arbitrary JavaScript is dangerous, but they don't.

Re:Hide this in your coworkers' JavaScript code tomorrow by moron4hire on Monday March 31, 2014 @09:58AM (#7501465)
I like what MDN does: https://dl.dropboxusercontent.com/u/9161524/Capture2.PNG

BTW, that warning is starting to drive me nuts.

Re:Hide this in your coworkers' JavaScript code tomorrow by notfoss on Tuesday April 01, 2014 @03:19AM (#7506628)
Re:Hide this in your coworkers' JavaScript code tomorrow by dang on Monday March 31, 2014 @02:48PM (#7503356)
By the way, we're going to penalize April Fools' jokes tomorrow so that they fall off the front page quickly. This isn't new, but we're going to be more systematic about it. The April 1 tech thing has become stale. If you guys see April Fools stories that we miss, flag them unless they're really particularly good.

People complain about HN's humorlessness, and they're right to a point. The trouble is that with a culture of humor comes a flood of lame humor. HN wants to optimize for intellectual curiosity, which wants higher signal/noise ratio. It's not that we're killjoys—we like jokes and laughing—it's that the signal/noise problem is hard.

Re:Hide this in your coworkers' JavaScript code tomorrow by chewxy on Monday March 31, 2014 @08:57AM (#7501100)
One of my favourite ways to punish JavaScript developers who don't use `var` is to randomly hide a

    if (false) {
      var GLOBALVAR;
    }
somewhere in the code.

It's fun (in a harmless fun kinda way, but you can also use some really dirty tricks to really hamper someone's work) to fuck up people's code - that's why I wrote Underhanded JavaScript. :P

EDIT:

Another fun one is to add `return`s to constructor functions.

Re:Hide this in your coworkers' JavaScript code tomorrow by watwut on Monday March 31, 2014 @10:09AM (#7501529)
How is either of those fun? I see why revere console logs are funny, if done when there is no time pressure and a lot of time available.

I do not want to work in environment where people feel that it is appropriate to routinely "punish" colleges by making them waste time like this.

Re:Hide this in your coworkers' JavaScript code tomorrow by chewxy on Monday March 31, 2014 @10:14AM (#7501554)
You could argue that "use strict" does the same, except it's language mandated. But yes, you have a point. These are not particularly fun, if you are on the receiving end. I've seen more than enough hair-raising bad JavaScript to last me a lifetime.

But you gotta admit, if you're on the pranking end, it could be fun to see someone tear their hair out.

Or my sense of humour is way out of whack. probably the latter

Re:Hide this in your coworkers' JavaScript code tomorrow by danielweber on Monday March 31, 2014 @09:52AM (#7501422)
I haven't had my morning coffee; can you explain what this breaks? I know JavaScript's scoping rules are unusual.
Re:Hide this in your coworkers' JavaScript code tomorrow by chewxy on Monday March 31, 2014 @10:04AM (#7501501)
Imagine you have inexperienced coders who do this:

    function foo() { 
        bar = function(){}; //define bar
    }

    function baz() {
        bar(); // use bar
    }
Note that both foo() and baz() could themselves, be inside another function. Doesn't really matter. Now `bar` is a defined as a a property of the global object.

If you add

    if (false) {
        var bar;
    }
in baz(), most developers, as I had noticed, will ignore it - afterall, it's a false condition, the code will never enter that branch. But because variables are "hoisted", you have now declared `bar`, it's lexically scoped as a new variable under `baz()`, with the value `undefined`.

So, when `bar()` gets called, it becomes an error, because `undefined` is not a function definition.

...

and yes, dear JavaScript developers, despite all the good efforts of people like Nicholas Zakas, Douglas Crockford, Addy Osmani and the like, bad JavaScript still exists in the wild. And I feel, in greater numbers than ever, and I am not optimistic that the amount of bad JavaScript will be ever reduced. This depresses me. Can't be helped, I guess.

Re:Hide this in your coworkers' JavaScript code tomorrow by mr_tophat on Monday March 31, 2014 @04:21PM (#7503860)
If this is the inexperienced way of doing this, what would be the correct way?
Re:Hide this in your coworkers' JavaScript code tomorrow by zupa-hu on Monday March 31, 2014 @10:15AM (#7501560)
It is only harmful if the developer actually used the variable as a side effect, aka relied on it outside the current scope.

By making the global variable local to the scope around the if statement, side-effects won't escape the local scope (as said, the if block does not declare a new scope).

Re:Hide this in your coworkers' JavaScript code tomorrow by brianchu on Monday March 31, 2014 @09:59AM (#7501471)
I'm not too sure either. In JS, block scoping does not exist. There are only function scopes, so the var declaration gets hoisted out of the if block (but the assignment occurs in the if block - so the assignment doesn't happen).
Re:Hide this in your coworkers' JavaScript code tomorrow by chewxy on Monday March 31, 2014 @10:18AM (#7501581)
Oh you can definitely fake block scoping in JavaScript, with ES5. ;P
Re:Hide this in your coworkers' JavaScript code tomorrow by mathias on Monday March 31, 2014 @09:04AM (#7501134)
For more, see the evil.js project: https://github.com/kitcambridge/evil.js

Also note that `string.split('').reverse().join('')` is not a very good way to reverse a string in JavaScript. See http://mathiasbynens.be/notes/javascript-unicode#reversing-s...

Re:Hide this in your coworkers' JavaScript code tomorrow by cfj on Monday March 31, 2014 @09:50AM (#7501409)
Evil.js looks like a lot of fun. Love that whole article, by the way. Very thorough.
Re:Hide this in your coworkers' JavaScript code tomorrow by chewxy on Monday March 31, 2014 @09:13AM (#7501190)
Oh... very very very nice. This is amazing
Re:Hide this in your coworkers' JavaScript code tomorrow by clux on Monday March 31, 2014 @09:53AM (#7501435)
Alternatively, put this in your code tomorrow to pre-empt all the April 1st bastards:

    Object.freeze(console)

Or safe JS up entirely: https://gist.github.com/clux/3823024
Re:Hide this in your coworkers' JavaScript code tomorrow by blinry on Monday March 31, 2014 @09:40AM (#7501343)
I did something similar in high school. You dropped a file named "System.java" into a Java project, which then intercepted all calls to System.out.println() and, for example, printed the text backwards, very slowly, or googled the text in Firefox:

https://github.com/blinry/fake-java-println

Re:Hide this in your coworkers' JavaScript code tomorrow by ijk on Monday March 31, 2014 @08:30AM (#7500957)
A silly prank, but it makes me wonder: has anyone implemented an antivirus/anti-problem scanner for open source code? i.e. scan the source code on a git repository and report any suspicious code that matches known malicious patterns? Lint, but targeted at detecting likely security flaws and code injections.
Re:Hide this in your coworkers' JavaScript code tomorrow by willvarfar on Monday March 31, 2014 @08:56AM (#7501091)
Coverity regularly scan open-source C/C++ projects and email contributors reports.

I've received a few such emails. Its a good way to market developer tools.

Re:Hide this in your coworkers' JavaScript code tomorrow by wavefunction on Monday March 31, 2014 @09:02AM (#7501125)
Sounds incredibly resource intensive. First, the sheer number of "open-source" projects which grow whenever someone has a new idea or some frustration with an existing solution. I guess you could try to limit the tool to a list of established projects but that of course limits the effectiveness of what you're trying to do. Established projects may be more attractive as a delivery vector due to widespread adoption, but there's also more eyes looking at the code giving a potentially higher chance of discovery of any exploits. And new projects have less-deployment and potentially more active contributors who might more easily catch some exploit slipped in.

Then there's the problem that you've got how many languages you need to scan against? And no quick way to determine what language a project is implemented in? Sure, you could add some sort of language detection in there but then you're adding to the overhead.

Finally, if the project has any sort of real complexity, some of the best areas to exploit would be in the integrations between two technology surfaces. Writing a tool to look for problems in a single contained module is one thing, writing a tool that can find problems in the interfaces between modules is quite a bit more complicated.

I think your "anti-problem" scanning tool would be the best avenue to pursue though. Maybe some sort of tool that would run on "checkin/pull-request" and look for issues like introduced buffer-overflow potential and things like that.

I think it's just easier to rely on solid projects with "known" contributors to police themselves and hope for the best, as bad as that may sound. Still, if you could create such a tool you'd make a fortune and improve the world immensely, so don't let my nay-saying stop you.

Re:Hide this in your coworkers' JavaScript code tomorrow by eropple on Monday March 31, 2014 @10:50AM (#7501771)
> Sounds incredibly resource intensive. First, the sheer number of "open-source" projects which grow whenever someone has a new idea or some frustration with an existing solution.

You should totally tell that to TravisCI, I bet they'd like to know. =)

Re:Hide this in your coworkers' JavaScript code tomorrow by tootie on Monday March 31, 2014 @09:49AM (#7501406)
Tomorrow, 8 people will commit this to our repo with zero net effect.
Re:Hide this in your coworkers' JavaScript code tomorrow by Trufa on Monday March 31, 2014 @10:30AM (#7501649)
This is pretty hilarious, would drive me nuts.

I once did a similarly annoying chrome extension just for fun: https://chrome.google.com/webstore/detail/annoying-typo-gene...

Randomly generates typo in inputs and text boxes.

Side note: Mihai, since I know you will be reading this, watch out if your arrays in LRTF are upside down ;)

Re:Hide this in your coworkers' JavaScript code tomorrow by sz4kerto on Monday March 31, 2014 @09:03AM (#7501131)
There's the old C prank: #define true false

.. but in reality, I had a serious issue with Qt once: #ifndef TRUE #define TRUE true #define FALSE false #endif

Now this screwed up some other library's similar definitions...

Re:Hide this in your coworkers' JavaScript code tomorrow by luch on Monday March 31, 2014 @09:21AM (#7501239)
Logic inversion should normally be caught rather easily, flow control misdirections not so much : #define if while .

My favorite (C++) : #define private public

Re:Hide this in your coworkers' JavaScript code tomorrow by twoodfin on Monday March 31, 2014 @10:06AM (#7501506)
My favorite (C++) : #define private public

Unless I'm mistaken, C++ was (deliberately) specified in such a way that such a redefinition does not affect the behavior of (most) already valid code. Access control doesn't affect overload resolution, for example.

I had to add the (most) qualifier because I bet dynamic_cast<> and other RTTI mechanisms would achieve different runtime results against some classes if private inheritance became public.

Also, I believe that C++ forbids preprocess munging of keywords under penalty of undefined behavior if you include any standard headers, so anything could happen in most modules.

Re:Hide this in your coworkers' JavaScript code tomorrow by npsimons on Monday March 31, 2014 @12:13PM (#7502333)
Unless I'm mistaken, C++ was (deliberately) specified in such a way that such a redefinition does not affect the behavior of (most) already valid code.

Perhaps it doesn't change the implementation, but I know I've used the above trick to get access to private functions for unit testing (yes, yes, I know you "should" only test interfaces, or make internal tests; spare me and realize it's useful: http://mrzechonek.github.io/tut-framework/faq.html#can-we-te...)

Re:Hide this in your coworkers' JavaScript code tomorrow by ape4 on Monday March 31, 2014 @10:42AM (#7501726)
Funny. Also subtle redefining of Linux commands tar -> zip.
Re:Hide this in your coworkers' JavaScript code tomorrow by ceedan on Monday March 31, 2014 @01:45PM (#7502968)
["-webkit-", "-moz-", "-ms-", "-o-", ""].forEach(function(prefix) { document.body.style[prefix+"transform"] = "rotate(180deg)"; });
Re:Hide this in your coworkers' JavaScript code tomorrow by mholt on Monday March 31, 2014 @10:40AM (#7501710)
#define while if

(C, obviously)

Re:Hide this in your coworkers' JavaScript code tomorrow by ultimatedelman on Monday March 31, 2014 @01:04PM (#7502695)
To anyone on my team reading this: DON'T YOU DARE :)
Re:Hide this in your coworkers' JavaScript code tomorrow by rquantz on Monday March 31, 2014 @01:44PM (#7502964)
This makes me glad I set up the workflow I did at our company. Nothing gets into the central code base without a pull request.
Re:Hide this in your coworkers' JavaScript code tomorrow by yukichan on Monday March 31, 2014 @08:53AM (#7501075)
Yes kill your coworker's productivity by making her or him even more miserable when dealing with a bug. If you did this and I was your manager, at worst you'd end up on a PIP. If you want conduct a prank do something that doesn't frustrate the work they're paid to do.
Re:Hide this in your coworkers' JavaScript code tomorrow by TomSawyer on Monday March 31, 2014 @09:44AM (#7501372)
Making the text print out in reverse is cute because they should be expected to have a "WTF?" second and then move on. I would expect that messing with the printed order of elements would backfire badly.
Re:Hide this in your coworkers' JavaScript code tomorrow by lscott3 on Monday March 31, 2014 @09:55AM (#7501440)
Ha, this is pretty cool.