I’ll give an example. At my previous company there was a program where you basically select a start date, select an end date, select the system and press a button and it reaches out to a database and pulls all the data following that matches those parameters. The horrors of this were 1. The queries were hard coded.
-
They were stored in a configuration file, in xml format.
-
The queries were not 1 entry. It was 4, a start, the part between start date and end date, the part between end date and system and then the end part. All of these were then concatenated in the program intermixed with variables.
-
This was then sent to the server as pure sql, no orm.
-
Here’s my favorite part. You obviously don’t want anyone modifying the configuration file so they encrypted it. Now I know what you’re thinking at some point you probably will need to modify or add to the configuration so you store an unencrypted version in a secure location. Nope! The program had the ability to encrypt and decrypt but there were no visible buttons to access those functions. The program was written in winforms. You had to open the program in visual studio, manually expand the size of the window(locked size in regular use) and that shows the buttons. Now run the program in debug. Press the decrypt button. DO NOT EXIT THE PROGRAM! Edit the file in a text editor. Save file. Press the encrypt button. Copy the encrypted file to any other location on your computer. Close the program. Manually email the encrypted file to anybody using the file.
There was something like
# sleep for about a second on modern processors math.factorial(10000)After it was found we left it in the code but commented out along with a
sleep(1)for posterity.In the readme: if you want this program to be usable, press the turbo button until the turbo light is OFF.
I saw one where the program ran a busy loop on startup to calculate how long it took. Then it used that as an iterations-to-seconds conversion for busy loops between scheduled actions.
That’s atleast pretty creative
Private key for a third-party API hard-coded into the front-end web app
This one is funny because it 100% still exists somewhere, but I haven’t had the chance to verify it again.
Okay so basically its a data recorder box (ex: brainbox) that connects to a bunch of industrial sensors and sends the data over the network with your preferred method.
Builtin firmware gives you an HTTP webui to login and configure the device, with a user # and password.
I think the user itself had a builtin default admin which was #0, which everyone uses since there wasn’t really much use for other users.
Anyway, I was looking at the small JS code for the webui and noticed it had an MD5 hashing code that was very detailed with comments. It carefully laid out each operation, and explained each step to generate a hash, and then even why hashes should be used for passwords.
Here’s the kicker: It was all client side JS, so the login page would take your password, hash it, and then send the hash over plaintext HTTP POST to the server, where it would be authenticated.
Meaning you could just mitm the connection to grab the hash, and then login with the hash.
I sat there for like 10 minutes looking at the request over and over again. Like someone was smart enough to think “hey let’s use password hashing to keep this secure” and then proceeded to use it in the compleltly wrong way. And not even part of like a challenge/handshake where the server gives you a token to hash with. Just straight up MD5(password).
It was so funny because there were like a hundred of these on a network, so getting a valid hash was laughably easy.
I never got to check if this was fixed in a newer firmware version.
The C++ code went something like this:
- Conver pointer to int
- Serialize the int over IPC to self using Linux Message Queues
- Delete/free the pointer
- Read the int from the queue
- Convert to pointer
- “Use” the pointer
Only reason I can think to do that is to “verify” the data in the pointer is not null/empty and is a valid int???
There are much better ways to do that but I can’t think of any other intent the programmer had.
Oh no, when they deserialized the int/pointer they used it like the original structure (which now points to freed memory). They meant to serialize the data structure across, but only sent the memory address.
Ok so this one is someone trying to move to “the cloud.”
They had a database they used. It was on a server in the office. We were tasked to clone the db server to a hosted VM. Due to order of creation this got put on a new host without anything yet on it.
They needed a site to site VPN to keep privacy, that was all fine. However after the clone and during testing, their guy there said that this one part was really slow. We take a look and everything is good with performance of the server and of the VPN. I have to pop on to take a look.
It was in an office app and written in VB. (I forgot which one.) It was indeed slower on the hosted server. So I took a look at the function (he got it up for me) and I could instantly tell the issue.
This part was a lookup page that searched for you input. The function retrieved the entire table, then filtered the results in the client. I explained that transferring the whole table over the internet would be slower than on the local lan.
This guy said he originally wrote this, but “forgot VB.”
In the end they decided not to update the app or keep the server in the office, but instead they rented some VDIs in the same data centre as the db.
Sounds like he didn’t have much to forget
I saw a talk recently, I can find the video if you like but pretty sure it was the most recent ND conference, where they made the point that a lot of lack of efficiency in modern code is because of large companies. Basically in alot of cases it’s more important to get a product out ASAP then to care if it was well done. Ok, a poorly written program may cost an extra $10,000 a month to run but if it earns them a million a month and saves 6 months of development time it pays for itself and they can eat the cost.
This seems like the case with renting vdis instead of fixing the program.
Lots. But one that springs to mind is a custom CMS where a new dev decided to print out the sql generated for a particular content type on paper. He took it to the CTO without comment.
What was wrong?
It was 12 pages.
Am I reading that right, that he printed out the generated sql query?
If so depending on context that may make sense to complain about. A 12 page sql query would be insane, something sounds like their are other issues.
That said I probably wouldn’t go to cto, I would go to manager or a senior dev and ask why it was so complex to get a particular content type. If there were no performance issues or bugs I would just ask out of curiosity.
Yes, the generated SQL query. It basically consisted of a lot of WHERE x IN (1,2,3,4) clauses for all the document IDs that matched something or other, and then repeated for the next JOIN. Small company, CTO was our direct boss and in the same open-plan office.
#4 is a good thing. ORMs do not make queries better or safer, they make them easier for devs that don’t learn SQL or safe calls. In some cases, they have been shown to cause slowdowns.
Weather forecasting software that maintains a linked list. When it eventually freed the memory used by the list, it would walk to the end of the list and free the last item. Then it would go back to the beginning of the list and do it again - rinse and repeat. Wonder why it was having performance issues 🙄
What were they storing in the linked list?
A bit late to the party on this one, but Facepunch just opensourced a bunch of their code, I nominate that.
I don’t recognize the name, what dud facepunch make?
Garry’s Mod. Rust (the game, not the programming language).
Ahh, ok yeah makes sense
Doesn’t that mean that your encryption algorithm and key is stored inside the code?
And since you are opening the code in Visual Studio anyway, just follow the function called by the “Decrypt” button, copy the function into another project and now you have a decryptor.I believe so but I don’t remember the exact encryption algorithm and don’t have access to the code anymore.
This was the same place that had a 500 line file named glob_vars.cs which you can guess the content of because “passing around variables cause memory leak issues”.
Long time ago, but by far the worst for me was when I inherited some code that a previous programmer had done. Every variable was a breakfast item. So if biscuit>bacon then scrambledeggs=10. Shit like that. It was a nightmare and luckily I only had to deal with it infrequently.
Why do people do stuff like this, is the logic not difficult enough to follow on it’s own without a secondary definition table to consult!? Fucking hell.
Had a programmer like this when I was still an apprentice. He was so full of himself. Was originally a Java programmer but had to program in PHP because that was what ran on the server. I never found out why he couldn’t just put Java on the server. We had full control.
All his variables were first names. Like
$klausand$grobi. Because he was afraid of clashing with reserved keywords. The thing is, in PHP all variables begin withexactly to prevent this issue. So he brought that habit over from Java which was far superior and not such a “Mickey Mouse language”.I mean, he wasn’t totally wrong, especially back then PHP was awful. But he surrounded every function with
and(PHP was designed to be combined with HTML output outside of these tags) and had plenty of whitespace between them and couldn’t fathom why all his html files had huge swaths of whitespace at the start.His way of preventing SQL injection was to look for SQL keywords in user input and then throwing an error in the log files.
I don’t know what’s worse… That program or that you put biscuits greater than bacon…
Actually I think the greater crime is biscuits being greater than bacon
but BiscuitTop + Bacon + Eggs + BiscuitBottom is definitely better than biscuit, or bacon or eggs.
True, all are good.
bacon++;
unless they’re bacon biscuits
I don’t know how old you are but when I was in school, this was just going out of style. They saw this as job security. If you’re the only one who can work on the code, then they won’t fire you
Oh god, that’s worse than I’ve seen where a SQL query joining 10 tables aliased all of the tables as a, b, c, d, e, f, g, h, i, j.
It was a mess, and as a new dev on the project, trying to figure out which where clause was for which table and how things worked was a fucking nightmare. Trying to keep a dictionary of letters to real table names in your head as you looked at the query was very taxing. In the end, I just fixed it all to stop using aliases. Or to use short abbreviations.
Here’s a mock example:
SELECT j.delivery_eta, c.cat_desc, a.part_number, h.region_label, f.wh_loc, e.emp_last, g.state_flag, b.mfg_title, i.ship_track_code, d.order_sum, a.created_on, j.last_scanned_at, e.emp_first, c.cat_code, g.state_level FROM parts AS a INNER JOIN manufacturers AS b ON a.manufacturers_id = b.id INNER JOIN categories AS c ON a.categories_id = c.id INNER JOIN orders AS d ON a.orders_id = d.id INNER JOIN employees AS e ON d.employees_id = e.id INNER JOIN warehouses AS f ON a.warehouses_id = f.id INNER JOIN inv_state AS g ON a.inv_state_id = g.id INNER JOIN regions AS h ON f.regions_id = h.id INNER JOIN shipments AS i ON d.shipments_id = i.id INNER JOIN logistics AS j ON i.logistics_id = j.id WHERE (b.mfg_title LIKE '%Corp%' OR b.mfg_title LIKE '%Global%') AND c.cat_desc NOT IN ('Unknown', 'None', 'Legacy') AND (d.order_sum > 1000 OR d.order_sum BETWEEN 250 AND 275) AND e.emp_last ILIKE '%berg' AND (f.wh_loc IN ('A1', 'Z9', 'M3') OR f.wh_loc IS NULL) AND g.state_flag IN ('ACT', 'PENDING') AND h.region_label NOT LIKE 'EXT-%' AND (i.ship_track_code IS NOT NULL AND i.ship_track_code <> '') AND (j.delivery_eta < NOW() + INTERVAL '90 days' OR j.last_scanned_at IS NULL) AND (a.part_number ~ '^[A-Z0-9]+$' OR a.part_number IS NULL) AND ( (c.cat_code = 'X1' AND g.state_level > 2) OR (e.emp_first ILIKE 'J%' AND d.orders_id IS NOT NULL) );That’s how mainframe programmers at my workplace do SQL. I think they do it due to long table and field names and narrow mainframe COBOL files
I have a friend that uses swear words 🤷♂️
So, this is completely off topic, but some of the comments here reminded me of it:
An elderly family friend was spending a lot of her time using Photoshop to make whimsy collages and stuff to give as gifts to friends and family.
I discovered that when she wanted to add text to an image, she would type it out in Microsoft Word, print it, scan the printed page, then overlay the resulting image over the background with a 50% opacity.
I showed her the type tool in Photoshop and it blew her mind.I am simultaneously horrified that she didn’t do any research to see if she could insert text into the image and incredibly impressed at her problem solving skills. Honestly, the more I think about it, the more I lean towards impressed; good on her!
Haha that’s so dumb. She could’ve just taken a screenshot!
I showed her the type tool in Photoshop and it blew her mind.
Or well. That.
Aw really wholesome actually. Some libraries in my area have senior friendly editing classes, I think it’s becoming more popular. Good looking out for them!
Photoshop is amazing. That said you kinda need to take a course in it to use 80% of the functionality.
And almost always, if you are not a professional, that could be done with any image editing program.
One time, I had to request firewall access for a machine we were deploying to, and they had an Excel sheet to fill in your request. Not great, I figured, but whatever.
Then I asked who to send the Excel file to and they told me to open a pull request against a Git repo.
And then, with full pride, the guy tells me that they have an Ansible script, which reads the Excel files during deployment and rolls out the firewall rules as specified.In effect, this meant:
- Of course, I had specified the values in the wrong format. It was just plaintext fields in that Excel, with no hint as to how to format them.
- We did have to go back and forth a few times, because their deployment would fail from the wrong format.
- Every time I changed something, they had to check that I’m not giving myself overly broad access. And because it’s an Excel, they can’t really look at the diff. Every time, they have to open it and then maybe use the Excel version history to know what changed? I have no idea how they actually made that workable.
Yeah, the whole time I was thinking, please just let me edit an Ansible inventory file instead. I get that they have non-technical users, but believe it or not, it does not actually make it simpler, if you expose the same technical fields in a spreadsheet and then still use a pull request workflow and everything…
The corporate world runs on excel, never the best option, but everyone knows it so…
Yep; I’ve seen excel files that at like 10MB because it’s a database in Excel
Try a few Gigabytes. I worked on site IT support for a year, we had to max out memory on a workstation because the company database was a, about 3GB, Excel file. It took minutes to open and barely worked, crashing frequently.
I’m so sorry.
I’ve seen a hotel booking made in Excel 🤷♂️
When I was interning in a cellular biology lab, I took their chemical inventory and converted it from excel to access. Complete with forms and reports. Spent some time training the permanent staff how to use it, explained how it was much more efficient than excel.
I don’t think they bought into it, but I tried.
I’ve had legacy systems that would encrypt user passwords, but also save the password confirmation field in plain text. There was a multitenent application that would allow front end clients to query across any table for any tenant, if you knew how to change a header. Oh and an API I discovered that would validate using “contains” for a pre-shared secret key. Basically if the secret key was “azh+37ukg”, you could send any single individual character like “z” and it would accept the request.
Shits focked out here, mate.
Rules I’ve learned from software engineering for almost 2 decades.
- Never roll your own ORM
- Never roll your own Auth
No matter what you think, someone else did it better. Trying to do either of those outside of a hobby environment is pure hubris. “But I can do it better” - no you fucking can’t. I have wasted much much more time debugging shitty “home grown” ORM solutions that clearly some dev just was bored and did than I have spent figuring out the quirks of whatever one I’m using. Same goes for auth. Just learn it.
Never roll your own ORM
I’ve done this. Probably 10 years ago. Even today, I maintain the same application that has the ORM in it that I designed. If I could go back in time and do something else, I’d do the same thing again. Honest to god. For my use case, I feel it was warranted. It was risky, but it worked out surprisingly well.
If I could go back in time and do something else, I’d do the same thing again.
So many questions here. What language? What’s the database? How many years of experience do you have in industry?
We are the worse evaluators of our own code, some of us are down right terrible but most people regret less significant code choices in a matter of months. The fact that you still think it is good 10 years later is a massive red flag.
Java, Postgres mostly but also LDAP and random in-house-written RESTful services, almost 20 years.
- The objects we store in the Postgres database are very “hierarchical” in nature, with one top-level object and lots of child/grandchild/great-grandchild objects. (We asked for a Mongo database but the infra team at the time said "make do with Postgres.)
- As I mentioned, some of that hierarchy is in LDAP or RESTful services, not in Postgres, so we needed something capable of dealing with multiple storage backends that would stitch the objects together as necessary. So the “ORM” needed to have backends for multiple backend systems.
- We knew clients would need a vast number of different queries. So we made a RESTful endpoint that gave the full power of the ORM to (authorized) clients. If they needed different data, we’d be like “change your query like this” and they didn’t have to wait on us.
- Early in the project, we consciously designed an extensible JSON representation of our hierarchical objects. That is what’s returned from the aforementioned RESTful endpoint.
- However, we also created a “shortcuts” system to allow us to “balance” how much of the logic lived on the server vs in the client. (It can mix and match. Like “apply this shortcut, but also filter this way and paginate” or whatever.)
- We made the API of the ORM such that it could both be used to query from the database/LDAP/RESTful systems, or be used as a client SDK for the aforementioned RESTful query endpoint that the application exposed.
- It’s both “more than an ORM” (querying from non-database sort of backends) and not fully an ORM (read only, doesn’t handle schema evolution.) But it’s fair to say it’s more “an ORM” than “not an ORM”.
- The implementation of the Postgres backend part of it is heavily inspired by Django’s ORM.
We couldn’t have pressed Hibernate into this use case. It doesn’t really deal with hierarchical data and sure as hell doesn’t know how to query from LDAP. I don’t know that anything existed at the time (nor am I sure anything exists now) that would fulfill our use case.
And the alternative to what we built was a massive, unmaintainable DAO with ridiculous numbers of individual queries in it that would have to be modified or added to endlessly every time someone needed to filter a bit differently or whatever.
The SVP over my org keeps wanting to design his own RBAC/Auth/IAM system.
We have entra, auth0, and keycloak.
The reason he wants it is he doesn’t want secrets to setup auth. Like that’s how it (mostly) works, sunshine.
The reason he wants it is he doesn’t want secrets to setup auth
Yes I’d like auth without the auth please
I never fuck with auth. If I can throw it up the stack I’ll do it as much as I can. When I can’t I find an open source solution and Im sure I still misconfigure it
I kinda rolled my own ORM, it was just a glorified class to SQL parameter converter that is then passed onto some SQL code. Then there was a thingy that marshals the result. Using table value functions in SQL standardises the result so any
select *just works. It was around 50-100 lines total.
I have to ask, if it’s only contains wouldn’t you get a ton of collisions?
Expecting an apartment manager to know what a api header was nevermind how to change it is probably not likely. Security hole to be sure though.
The secrets themselves were basically guids, they had quite a lot of characters. If sent MORE than 1 character, pretty low chance they would clash. But those long guids also covered a lot of letters and number - it wasn’t terribly difficult to find one single character that cleared authorization reliably.
And maybe you’re joking lol, but multitenant meaning multiple businesses/customers using the same application stored in the same database. If Bob’s construction wanted to spy on Jim’s contracting, they’d just need to know the right header to send and could get whatever they wanted from the other customer partitions. User access should of course be limited to their own assigned partitions.
Oh, ok I interpreted multitenant wrong. I was thinking it was like a apartment complex so you have like a manager and a sales person with access and that’s it. Still a valid security risk but not as severe as what you are saying now.
Sorry for confusion
I once saw an application that would encrypt (not hash, encrypt) passwords but then when a user was logging in, they’d encrypt the password candidate and then compare the cipher texts to see if they were the same. This was using 3des, so no IV.
Floats for currency in a payments platform.
The system will happily take a transaction for $121.765, and every so often there’s a dispute because one report ran it through round() and another through floor().
Presumably every so often there’s a dispute because 0 + (0.3 + 0.3 + 0.3) - 0.3 - 0.3 - 0.3 is not equal to 0 (in floating point arithmetic).
And not the easy way of using (long) integers to count the cents.
Lmao.
Using floats for nearly anything in a finance platform should be grounds for immediate dismissal.
Did either of those do banker’s rounding?
Round is the safest way of using decimals for money as it corrects 10.499999999 (decimal fractions can’t be stored precisely in floats as binary can’t precisely represent all 2 digit decimals) to 10.50, where floor would take it to 10.49
It is safer to count in cents and have a policy to handle fractions of cents from divisions
deleted by creator












