by BatteryMountain · 1mo ago · 0 comments
On our own 1.5M loc system, we've found and fixed thousands of bugs, security holes and circular dependencies in the last year. Code quality has increased, test coverage increased. We've also recently set our compiler to treat warnings as errors, and to be as strict as possible. It is absolutely amazing to see the gaps being filled, it would've been an impossible task for human devs and IDE's would've made it very uncomfortable. We've also ironed out all the bugs and failure modes in our infrastructure automation / monitoring. Our next project is to eliminate all 3rd party dependencies, and after that to rebuild our frontends completely using zero frameworks, not touching npm ever again after that.
So when I read this about postgres, I was very happy that they found and pursued this side quest. They can make the codebase bullet proof.
The only "third-party" packages that we want to ideally allow/support would be provided from LTS versions of our runtime (in this case, packages provided by the dotnet team and audited by microsoft). So we will always try to build around what the framework provides. Second choice is our own code, third choice is open-source packages, fouth choice is a separate application/appliance (lets say ZenDesk for ticketing). Over time, we will reduce this footprint to only have dotnet team code and our own.
Remember most CVE's can be hidden on servers that are not publicly routable and don't have a real exploitation paths. The bits that are public (lets say a linux edge server with a web server on it, some firewalls, a couple of open ports) - these should be hardened to the max and not allow full access to all the services running behind it. We don't even give our internal services public IP addresses to make near impossible to route traffic to them.
Our git repo's are also not on public infrastructure (serious, think carefully about hosting on public services and if you really need it), never mind making the repo public.
We also have a dedicated secrets/certs manager, so no credentials are in codebases or pipelines. Very strict in this regard.
The thinking of "it's inside so we're safe(r) from attacks" is a false sense of security, as (e.g.) Maersk learned with NotPetya:
* https://www.wired.com/story/notpetya-cyberattack-ukraine-rus...
From the year 2000:
NAT (particularly NAPT) actually has the potential to lower overall
security because it creates the illusion of a security barrier, but
does so without the managed intent of a firewall. Appropriate
security mechanisms are implemented in the end host, without reliance
on assumptions about routing hacks, firewall filters, or missing NAT
translations, which may change over time to enable a service to a
neighboring host. In general, defined security barriers assume that
any threats are external, leading to practices that make internal
breaches much easier.
* https://datatracker.ietf.org/doc/html/rfc2993#section-9Kind of works until the TV, the fridge, a user's BYOD or your printer has infiltrated your LAN.
So it kind of doesn't.
also some 3rd party libraries are overdesigned/overcomplicated because everybody wants the library to do everything for everybody.
This overcomplication can easily introduce security problems that is not present in the 1K solution.
Also a source of significant dependency churn even excluding security bugs.
Whereas with my own code I don't have to worry about scheduling work that's only arisen because somebody outside my organisation has decided to make a breaking change in a dependency. Paying that tax got old over a decade ago, and my patience with it now is close to zero.
Of course, sometimes simpler is “I stored the passwords unhashed”, so you have to find the middle ground.
For example, a few years ago I removed a rather large 3rd party mathematics library because we were only using it for a single mathematical function that was very easy to replicate.
Remember, 3rd party libraries need to:
1: Be periodically audited to make sure you are in compliance with the license terms, and preferences of your company.
(1.5: This becomes important during an acquisition as someone will always come around doing due diligence.)
2: Be periodically updated (in case of security bugs)
2.5: Be updated on short notice when a security issue is revealed.
In the case of the mathematics library, replacing it with roughly 20 lines of code and 100 lines of tests is a significantly better tradeoff than constantly reviewing it every time one of the above things happens.
Now, at what point is it "worth it" to use the 3rd party library? In our case we'd need to make much heavier use of the library, probably at least 20 different mathematical functions from it.
Sure I shouldn’t roll my own crypto but I can write a logger…
Also any part of the program can send data to the logger. This means the logger can receive malicious payloads from anywhere. Maybe your logger handles ascii control characters badly?
The only even slightly tricky part is like "don't mess unicode up", rest is straightforward. Sure it can be complicated with logging sinks, configurability, when to flush, monitoring and so on but in many cases you just don't need all that. You just build it whenever you do need it.
Capture log messages and write them directly to stderr? That’s easy.
This is where the LLM coded library replacements make sense. When you have non-critical code that can be easily swapped, I’m happy to let an LLM generate a logging package. If I have a need to send log messages out to a separate server for archival? I’d be a little more critical.
But crypto really is just a small thing. I’m not going to design a nuclear reactor but I’ll definitely do stuff that depends on the electricity from one. Similarly one can still do their own authentication; its not like even Apple forgot to rate limit…
> just in your own code that is less well audited than public libraries
why do you think public libraries, which change all the time, get deprecated, handed off and supply-chain attacked are well-audited in any way?
If you spend a ton of time hardening your own library code and don't have much feature sure, then that can be a win.
Security through obscurity protects you from low effort vulnerability scanners.
It makes you more vulnerable to a sophisticated targeted attack. A competent hacker or AI will quickly find vulnerabilities in your custom libraries.
I don't know were it will leave us in the long term and I don't think I'll like the answer.
Only where the AI solution is verifiable by the dev doing the promoting and review. Cryptography is probably better served by libraries vetted by experts.
So why wouldn’t a competent AI find those vulnerabilities during development? I don’t think the proposal is to have human devs hand write the custom libraries and yolo into prod.
It probably would. Except it’s internal, and not a reportable CVE, so the fix will be deferred.
To be fair, there is more nuance to your statement.
A lot of it depends on your programming language.
For example with Go, with its extensive and excellent stdlib, you would be foolish to rely on large swathes of 3rd party libraries, because so much can and should be done using the Go stdlib.
On the opposite end of the spectrum, you have Rust with an effectively non-existent stdlib.
And the problem you see frequently with Rust is projects importing half the internet, with a Cargo.toml the length of your arm with hundreds of dependencies. Of course the project has never reviewed its dependencies source code, and the project probably barely keeps its dependencies up to date. Its a supply-chain attack waiting to happen, not if but when.
So with languages like Rust, you have to take an approach of "minimal reasonable dependencies", make an active effort to keep your dependency list short and in-control.[1][2]
> less well audited than public libraries
I also struggle with this particular argument because the reality in open source is "well, its open-source, it has many eyes" is in fact mostly a dream. Since we all know 99% of the time its a small group of maintainers (assuming there is are even multiple maintainers[3]) and not many (if any) external reviewers.
[1] https://tweedegolf.nl/en/blog/119/sudo-rs-depencencies-when-... [2] https://tweedegolf.nl/en/blog/104/dealing-with-dependencies-... [3] https://xkcd.com/2347/
What a bullshit.
It's different scenario, different trade offs.
You mitigate risk of library being sold to malicious 3rd party, you avoid risk of your supply chain being hacked, you avoid API/behaviour breaks, etc.
The trade off is that you have to maintain it.
That's why dotnet's ecosystem is so loved due to MS providing 90% of needed libraries, so you avoid some 3rd parties maintained by single person.
Often it can be a very good choice to write the functionality yourself and not rely on external libraries.
And since we now have coding assistants, maintaining in-house costs near nothing now. Nobody else can break us, only ourselves.
Let's hope this is the future of Software Development. There is so much to create yet.
Companies will do different things, just like they did with mobile, the internet, and computers in general.
Some strategies will work, some will fail.
AI is getting so good, it will probably be both.
>set our compiler to treat warnings as errors, and to be as strict as possible
>ironed out all the bugs and failure modes in our infrastructure automation / monitoring.
>eliminate all 3rd party dependencies
>rebuild our frontends completely using zero frameworks
Oh yeah, that's what i call "software engineering" and excellent use of LLM's! Great to see Company's with a Mindset like that.
Genuine question, because I don’t know: Wouldn’t it suffice to vendor your current packages and “only” stick to maintenance from there on out, instead of rewriting it all?
This should still achieve the goal of not needing to touch npm, but presumably with less effort/tokens, right? Or is it just that you would expect the result of that process to be less clear and maintainable than a full rewrite?
How's that going? Any lessons learnt you'd be willing to share?
Mmm what else. I prefer postgres so I'm very excited about this. So many foot-guns will no longer haunt us like on MSSQL and less db/table locks to try solve (pessimistic vs optimistic locks). Oh and we are going to save a gross amount of money per year, as we will also be able to switch off a couple of Windows Server VM's in the process. These puppies are costing us a ton (I think about half of our infra bill are licenses...).
Just create a branch, spin up a test db and try to port a small feature. Its very easy in most cases. Debian + dotnet + postgres = dream team.
Maybe you don't need all of Postgres - so provide 2,3,4,5,n versions. As long as every version is covered by (possibly shared) tests, then you can release what works, ignore the rest (bugs and all).
It's also crucial to scan for "analogues" because otherwise many LLMs autoreport as "not vulnerable" since "this applies to Postgres/whatever and this repo isn't using it"
If you get hit by cyber guardrails you should use a local model to prune any CVE specific language from the reports.
To give examples, every single LLM (and people too tbh) will write netcode that's vulnerable to these CVEs: CVE-2026-27135, CVE-2024-45311, CVE-2021-32567, CVE-2019-9511; without explicitly mentioning the CVE text no LLM finds these either.
Just remember the golden rule of crypto is to never fool yourself into thinking you can write your own crypto libraries.
You can go with "eliminate all 3rd party dependencies [...] frontends completely using zero frameworks" and be stuck with JS. Or use a typed language (TS, ReasonML/ReScript or even Elm) and an API client generator (available for all those languages) and get type safe API calling from a more strongly typed language.
As much as I prefer not to use NPM and even more prefer (even my LLMs) barely touch JS. A bit of safety is cheap these days, as you rightfully pointed out.
Does management appreciate it? Do customer see any value in it?
Good. That's how it should be: do not trust motivated engineers, trust a text generator that has no clue nor responsibility instead.
/s
I could imagine scenarios where only well off developers and companies could afford that.
Then if you don't have the money, you are out of luck and risk having vulnerabilities in your code.
And it takes just one adversary to pay the bot & the bot will happily find an exploit for them in your code.
This worry this could lead to a serious power imbalance & furthe damage the free software community...
1. The cost of running AI is dropping down to "free" - there's open weight models, open source tools, and guides on running your own if the long list of suppliers isn't good enough for your use cases.
2. Vulnerabilities have always been a risk; AI is not a panacea. The pre-AI best practices still apply. Furthermore, a huge percentage of vulnerabilities are in 3rd party tools and systems, which are systematically being scanned and fixed and/or exploited, then fixed.
You mention "the free software community" in your last sentence though - this implies the code in question is open source, so it's able to receive plenty of improvements from anyone with access to these tools.
Worse case, we enter the Dark Forest era for technology. Read up on this concept and apply it to the tech industry. I suspect open-source might die and everything becomes private, no more public networks, no more open access, as to assure survival. In a sense we are halfway there already as it seems the internet is starting to close down, people not posting their art and music as much anymore, not posting their knowledge for free anymore, as it might be used against them by AI (the other party in the dark forest..). Thus private authentic experiences will become more valuable.
Before we started this journey (about a year ago), we spent a ton of time cleaning up our codebase, splitting large files (10K+ lines) into files that are no more than 2K lines, things like that. Then we let claude scan our important files and summarize them, add comments for future claude sessions. So we've let it built up tribal knowledge per file and the reasons for things to exist. We tell it all about our operating environment, the country and legal framework etc, so every little piece helps it stay honest and on track.
So to start, do something simple like: Scan the files in this folder for database code and check for queries that loads the entire result set into memory and/or queries that loads all columns. Suggest which queries we can filter better or reduce columns being transferred. Once done, also check real db row counts, compare them with the queries in these files and check if they might benefit from an index or partitioning/sharding. Also check for queries that loads data but their results are not used. Don't make changes yet, just do a deep investigation and report back. Feel free to spin up muliple agents to batch the scans.
edit: it goes without saying you need a language with strict typing and a good compiler (we use dotnet). Doing this on python/javascript would be a nightmare.
I still have yet to see this be efficient. The time I spent doing this is way less efficient than simply giving the LLM some high level direction and putting that time towards reading the code it generates and correcting small piece by piece (occasionally doing things manually, but that’s only for more off the rails stuff).
It’s about the same amount of time as up front planning, except I know the code much better as well as end up with less mistakes compared to having it implement a front loaded plan.
Knowing the codebase makes everything else 10x more efficient too - triaging bug reports, planning other work, knowing what work needs done (this is a big one), reviewing PRs, etc.
Would you mind elaborating?
Oh it also helps to split refactoring work into three buckets: business logic changes, performance changes (same output as before but faster) and cosmetic changes (rename files/folders/classes, breaking large files up, add logging/comments, domain layering etc). We tend to focus on performance and cosmetic changes for bulk refactors and leave logic changes to more dedicated sessions as to avoid changing what the system do (our domain is fairly complex and we cannot afford breakages). We also managed to port ALL of our code to dotnet 10 lts and have clean boundaries between projects (we have a mono-repo with about 50 projects in it), so we can wholesale upgrade dependencies without a sweat.
Of course, crashes and bugs can happen when applying quickfixes, which isn't nice. Ideally, they should be reported and fixed. You can also ask an agent to fix the occurences instead of using the IDE quickfixes if that's blocking you.
I guess what I'm trying to say is that IDEs shouldn't make that process harder, they can actually improve agents' results. For example, you don't need to write custom skills to prevent agents from writing some class of bugs if the IDE can detect it and agents have access to the results.
> Changing 200K+ lines of code yourself is a nightmare (and to prove it still does the same thing afterwards).
If an agent does it, you still have no proof, but okay.
Full disclosure, I work at JetBrains, but not in the IDE department.
Where now, the compiler flags & strict analyzer settings forces claude to do the right things (we explicitly tell claude not try and bypass or lower the barrier). I think it only works because we don't spend 95% of our time in the IDE anymore like a couple of years back, so we as developers no longer feel that friction, as claude tries to satisfy the compiler instead. Its a massive mental load that is just gone, we haven't had any conversations in meeting about this kinda stuff anymore (remember in the past we would have flameouts in meetings or code reviews about linter settings...).
Do you have a specific skill to guide an agent to scope the work of an agent so it stays in one particular bucket? Would you mind sharing it?
Overall, there's much less need for prompt skills anymore. They're still very useful for things like best practices, or things you need to make as reproducible as possible, but big skill and planning sessions aren't nearly as necessary anymore.
Wow, the innovation! I am so glad we have this AI thing!
> Code quality has increased, test coverage increased
And of course - two meaningless metrics.
The third party dependencies are also using AI to improve their code.
What's the proportion of bugs you've encountered that was due to a library versus due to your own code? I suspect it's probably more than 1:1000.
This is a stupid decision.
For me it’s less about bugs and more about supply chain security risk. And with AI and only building what I need from a dep, exactly how I need it, the cost of doing this is very low.
It's a nice idea, and in theory sounds great, but you may be trading 1 library with 1000 bugs for 1 million implementations each with one special bug...
Perhaps your workflows and processes are so efficient that this actually makes sense. But I’m still not convinced AI assisted development is at that point yet; I think the classic Build vs. Buy arguments still hold.
How much is this going to cost to maintain? How many dev hours? How many tokens? Is your in house solution going to provide the business and customer enough perceivable value that it’s worth the opportunity cost? Are you going to apply the same rigor and security testing that the popular frameworks are getting from the largest research firms in the world? How do you know the LLMs aren’t going to apply similar patterns and make the same mistakes? Why can’t you just use that AI expertise to accelerate patching so your exposure time is limited? How do you know you’re going to outpace the major frameworks and tooling providers in 2 or 4 or 6 years when they catch up with AI assisted development, if they haven’t already?
And very personally speaking, I’m still holding my breath to see if this AI bubble is a real thing or not. Because if it ever pops, well, that’s not going to go well for companies that are embracing this stance.
But the gp said it is, and gave examples.
> Code quality has increased, test coverage increased.
And that's true for many old codebases!
> We've also recently set our compiler to treat warnings as errors, and to be as strict as possible.
Yeah. Everybody who said it was impossible, that no budget would ever be allowed to fix old bugs, that new features "to support the business" was the only thing that mattered and other nonsense like that have been proven wrong. Arguably they were kinda right but then LLMs happened and that's what proved them wrong.
I love to see what's happening: at very long last people are understanding that security is something to be taken seriously. They're understanding that "more code = more bugs".
> Our next project is to eliminate all 3rd party dependencies,
I love the spirit!
> and after that to rebuild our frontends completely using zero frameworks, not touching npm ever again after that.
I hope many more shall realize that now we can give the middle finger to a great many pathetically bad and totally unfixable (even with the help of LLMs) ecosystems.
AI-slop reports are filling up the queue and taking away time from volunteers. So contributing to delay in releases/features.
No. Debt is a tool. Sometimes it’s good to pay it quickly, but sometimes it’s better to pay it as slowly as you can.
You never wanna intentionally repay tech debt as slowly as possible. You might be able to tolerate/ignore it for longer depending on the circumstance, but you always wanna get rid of it sooner rather than later.