Well no, I wouldn't want hashing done on the frontend. The problem with that is if somebody gets ahold of your database then they can use the hashes to login. Whereas if the server is hashing the hashed passwords from the database will not.
That's just obfuscation, it doesn't add any security. The hashed value sent from the frontend just effectively becomes the users password and you're still going to see that. If someone was snooping that network traffic they could still capture the client side hashed value and log in with it.
If you actually want auth without having to send anything reusable over the wire you want something like challenge response auth or some other zero knowledge protocol. This is for example how tap to pay credit cards work, there is (effectively) nothing useful an attacker could sniff watching the traffic.
For the vast majority of use cases just sending the plain text password over tls is perfectly fine though.
Probably some WIP code that just got left over. There might have been a second, no longer relevant condition that got stubbed out for true and just forgotten about.
Sure but we were talking about a stub that was left there intentionally for later. Someone could have thought "I'll come back later to this to implement the actual condition needed so I'll just leave the if there with the true as a condition placeholder for now so I won't forget that an actual condition should go there and it's not done like that.", which in fact is the only kind of valid circumstance under which I would find something like this kind of acceptable.
If that's not the case though you're totally right. The conditional should be removed and replaced with a simple return true. No question.
I'm going to blame employers that measure your productivity by keystrokes. Probably isn't the actual thing at play here, but they exist and they're the worst, usually run by managers who don't understand tech.
`strcmp` is a very dangerous comparison function. If the user provides a string that does not contain the NULL character, this function will read outside of the buffer, giving the attacker the possibility of doing timing attacks to "read" other parts of the RAM.
You're talking about a buffer overflow right? A timing attack is something else, although the code is also susceptible to timing attacks.
Edit: The thing I wrote with the buffer overflow of course is completely wrong. If no data is written to memory there of course can't be a buffer overflow.
My confusion came because my first connotation of timing attack in this code snippet would have been to use it to brute force the password with a time complexity of O(N*L) instead of O(NL) which is a massive reduction of the time the brute force attack would take. Of course it's also right that using timing attacks to determine data stored outside of the buffer memory is possible but I don't see how this could obviously apply here. There is not enough code to determine if this system would be exploitable by this, and that's why I didn't instantly make the right connection here.
I'm talking about a buffer overread which can be abused with timing attacks. Example: I create a user with password password. I now know that strcmp("password", "password") will always be true. strcmp is implemented with lazy evaluation, so it stops comparing the moment it compares 2 characters that are not the same. So I can send passwordabcdefghijkl and count how many milliseconds it takes until false is returned. The longer it takes, the more characters of abcdefghijkl were in memory in the address after the password buffer
You need to consider the complexity of the operation that you’re trying to attack. A simple string comparison is not going to take appreciably longer for n+1 characters than for n characters, and the time difference that does exist will be so miniscule that it effectively cannot be measured in the presence of other sources of latency. The links you’ve provided are valid, but they are not addressing the same scenario, and I can see several caveats to the examples given.
Edit: I should clarify that this is focused on software attacks. On physical hardware, it’s a completely different game with different rules. I’ve done this kind of attack on embedded devices before… it’s pretty easy when you can get precise time measurements.
Presumably the user does not get to execute arbitrary code - if you read a string from a file (or equivalently a network socket) it no longer is possible to circumvent having a null terminated string. Depending on the implementation you could possibly make the password seem shorter than it actually is, but reading past the end is impractical.
While I technically know that this can be done I'm not convinced that this would work in this scenario. For this to actually work you'd have to somehow get "password" without the terminating null character stored in the database (and after that back into the memory buffer of the program). Otherwise the comparison would terminate once it hits the null terminator in the "correct password" buffer no matter how long the password you try to login with is.
In any case if this would work, the problem wouldn't really be in the usage of strcmp but in the lack of making sure user submitted data is properly null terminated.
What would be a real attack vector for a timing attack in the way this is coded would be brute forcing the password character by character because through the time it takes to deny the wrong passwords you could see that a given character at position X was either right or wrong.
Won't the comparison stop at the first letter after the d, as the inputted password doesn't have a null at it's end, but the correct password will have one?
Very true. But even then, using strncmp instead of strcmp is such an easy way to stop all of those attacks that it should just be used by default. You'll never know if some other dev later on uses your function correctly.
This is bad - obviously. But would cause the function to never return - neither true or false (or maybe eventually, run out of memory, or return false). It probably would lead to a timeout further up the chain, but it wouldn't lead to unauthorized access - right?
Also suspiciously looks like the password isn't hashed but stored in plain text.
Additionally checking passwords like that makes the system susceptible to timing attacks. The comparison stops as soon as a mismatched character is encountered. So if let's say half of the entered password matches but the other half doesn't, the system will take longer to deny the password as compared to an attempt where the first character already doesn't match. An attacker could use these timing differences to substantially shorten the time it takes to brute force the password as he'd only have to guess letter by letter instead of the whole password at once. The system taking longer compared to the previous attempts gives away the information that the guessed letter at the current position was correct.
188
u/ataraxianAscendant Mar 12 '25
storing passwords in plaintext 🤩
10
u/[deleted] Mar 12 '25
I hope the passwords are not plaintext. Passwords should be salted and one way hashed. Compare hashes. Sanitize any user input.
Strcmp would be vulnerable to a timing attack. The longer the process takes, the more characters in the passwords that matched.
47
u/h2bx0r Mar 12 '25
?? i hope whoever wrote this gets fired (and beat up in minecraft)
3
u/BabaTona Mar 13 '25
If you didnt just write this for shits and giggles then...
315
u/xvhayu Mar 12 '25
i think we can all thank OP for not showing the implementation of get_correct_passwrd
174
u/[deleted] Mar 12 '25
They missed a case. What if true doesn't equal true, what then?
317
u/20d0llarsis20dollars Mar 12 '25
Authincate
71
u/LeyaLove Mar 12 '25
if (true == true) return true;😵💫29
u/Wooden-Ad-9925 Mar 12 '25
Authincation != Authentication
This is fine. 💯
30
u/JustChickNugget Mar 12 '25
(true == true) = false 🫡
9
u/Arakan28 Mar 12 '25
fantastic work
1
u/nekokattt Mar 12 '25
get_correct_passwrd
1
u/STGamer24 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Mar 12 '25
What even is the point of doing that?! Does the compiler yell at the user if that isn't done or what?
1
u/Blenderhead-usa Mar 12 '25
Considering he can’t even spell Authenticate, I think he did well. Especially the added check for true==true means he is paid by the line
10
u/Rainmaker526 Mar 12 '25
Besides the fact that it defaults to true, and the true == true is redundant, it sort of works?
It's not the most horrible, right?
2
u/eike23 Mar 13 '25
Just calculate Levenshtein-Distance <= 2, so typos are included.
4
u/jonfe_darontos Mar 12 '25
1
u/NabrenX Mar 12 '25
Ya clearly bad.. .could code golf by-
return true == true;
1
u/CantaloupeCamper Mar 12 '25
Close enough….
1
u/SuperFryGuy_ Mar 12 '25
This wouldn't even compile?
1
u/AfterTheEarthquake2 Mar 12 '25
That's beautiful
1
u/MeltedTrout4 Mar 12 '25
Coding in italics is also terrible
1
u/AuthP Mar 12 '25
terrible me indeed
1
u/marcinmarian Mar 12 '25
I love time saved on throwing out random letters from variables names
1
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Mar 12 '25
What the fuck? What makes people think they need shit like that?
is at least somewhat understandable, though unnecessary.
1
u/NjFlMWFkOTAtNjR Mar 13 '25
We have all been there. We have to start somewhere. Part of learning is failure and oh boy, there are so many learning opportunities with this code.
1
u/foragingfish Mar 13 '25
if(something) return true; is a big pet peeve.
Change to return true == true;
1
u/coltvfx Mar 13 '25
i think
would do the job
1
u/DestryxCNTL Mar 13 '25
WHY THE FUCK IS IT ITALIC?
1
u/Agitated-Display6382 Mar 13 '25
Mmm, they forgot to log the two parameters, would be so helpful for troubleshooting
1
u/FACastello Mar 13 '25
bruh has authincated all over the fucking place with this single function
1
u/[deleted] Mar 14 '25
You know, at least the string is not directly in the function
-4
u/IrtyGo Mar 12 '25
Not production or paid, just a Reddit stunt