One more auth system that will give you nightmares...

This JavaScript code powers a 1,500 user intranet application.

The longer you look at it the more insane it gets.

@LoganDice The icing on the cake is the todo comment on top.

Like putting it in a different file is the LEAST of your concerns here. 🤣

@logicallysound @LoganDice even more egregious is the use of an HTML comment... you could just use a JS comment inside the script tag
@jacobherrington @LoganDice Honestly I think that's less egregious. The HTML comment is more visible on a quick scan of the overall HTML file than a JS comment inside the script would be and it's easier to interpret the TODO as applying to the script tag as a whole.
@logicallysound lol I just think <!-- --> is a terrible way to write comments. 😆 Code style is 99% preference.
@jacobherrington I've never liked how HTML comments look so I can sympathize on that point 😅
@LoganDice Why are there 3 ='s for the logic tests?

(yes, there is a LOT more here....)
@kemonine @LoganDice actually, `===` is usually a good idea because you avoid accidental type conversions.
@kemonine In JavaScript, `==` performs coercions so that e.g. `2 == "2"` is true. The `===` doesn't, acting much more like `==` in other C-derived languages.
@LoganDice my favorite part is the three exclamation point todo at the top
@csalzman @LoganDice Yeah, definitely put this in a different file, and then delete that file.

@LoganDice if ("true" === "true") { return false; }

*chef kiss*

@LoganDice wtf it just iterates over every account until it hits the right one??? with 1500 users???? also what the hell is going on at line 556? shouldnt there be hashing involved?


oof.

@postmasterdoggo

Not to mention that it's a frontend code, so anyone can see all the user's info. And execute arbitrary sql, if you want to drop all tables for example.

@LoganDice if I understand whats happening here then.... Fired 😵
@LoganDice
H O L Y
F U C. K I N G
S H I T 😱
@LoganDice There's like 70+ levels of WTF in this compressed to just those few lines.
@LoganDice I am not sure why but I kind of want to frame this and hang it on my wall 😐 Can't tell what's wrong with me 🙄
@LoganDice Are... are you going to fix it? Please?
@LoganDice "PUT THIS IN A DIFFERENT FILE" ➡️ 🗑️
@LoganDice I hurt my throat laughing, thanks!
@LoganDice at least they used triple quotes
@LoganDice i was gonna mention that at least it doesn't seem that there's an injection vulnerability, then i fully caught on that this is running in the client...

@LoganDice

That is going to give me nightmares.

@LoganDice A reply from a friend of mine who read this toot:

"Don't think of it as a security vulnerability, think of it as backing up your user database on every client" 🤣

@LoganDice I think at some point in my life I have written intranet code like this. (Not in JavaScript though. JavaScript didn't exist back then.)
@LoganDice it will be way more secure when moved to another file!
@LoganDice I love everything about this. this is art

@LoganDice raw sql exposed, severe language weirdness, unhashed passwords of all users sent to anyone on every login attempt and then "logged in" is just a cookie you can set arbitrarily anyways and there's *still* more…

Truly astounding – it's like a masterpiece of horrible software engineering.

@LoganDice You. Are. Kidding. Me.

So many layers of SHIT NO!!!

@LoganDice better put that in a different file!
@LoganDice is there an actual purpose to `if ("true" === "true") {`, or is it just more bonkers shit?

@LoganDice

I'm kinda curious about that "True" === "True" at the bottom. Is that an established JavaScript idiom with a well known purpose? Or is it just there?

@mds2 @LoganDice technically it evaluates to true, but it's not remotely ideal.
@LoganDice please tell us where this code is deployed??

@LoganDice this is wrong on so many levels!
- passwords are not encrypted.
- open to sql injection (there still can be mean people on intranet)
- you are fetching the entire datatable!

My eyes are bleeding at the moment. And that’s not because of the monokai theme :)

@LoganDice Wow! 😳 That's... something.
@LoganDice Oh. Oh nooooo. This is driving me mad already.
@LoganDice
Everything about this is frustrating except lines 556-558, which are just dadaism.
@LoganDice okay I know _zero_ about javascript but... `if ("true" === "true")`?????
@LoganDice At least it's not vulnerable to sql injections.
@LoganDice my reaction on reading this code:
why
SQL is designed to do this, why
*why*
WHY
  
@LoganDice This is all client side? Oh My...😆
@LoganDice I don't even have words...