r/reactjs • u/Opening-Gazelle-8196 • Jun 22 '26
Needs Help How are you catching hardcoded api keys from ai scaffolding before they hit the repo
Ive caught three hardcoded api keys this sprint and every one came out of an ai scaffolding session where the model inlines a key to run the sample and the dev forgets to strip it back out. one was a live stripe key that only spotted because i happened to be reviewing that PR by hand and id rather not rely on luck for this.
once it gets past the commit its in the git history anyway and a scanner that flags it a couple weeks later isnt much help by then.
We're mostly frontend and theres not many of us so im looking at gitleaks or trufflehog for a pre-commit hook. only problem is it fires when the dev has it installed and eventually someone reclones or sets up fresh and skips that step, so i probably want a server side check as backup too.
How are you all dealing with this and where did you end up putting the check so it doesnt drag every commit out
55
u/Mestyo Jun 22 '26
This industry has fallen so far.
Sorry, I don't have any solutions to offer. This just shouldn't be a problem.
28
u/Dan6erbond2 Jun 22 '26
If sample code and secrets are hitting the repo then the problem is that your "devs" are just glorified prompt "engineers".
16
u/pepedlr Jun 22 '26
Read your code. 👍
7
u/SureBockal Jun 22 '26
I think the only way to handle this is to renew the api key and change it in the program. Once the key is exposed to the internet it‘s to risky to use it …
7
u/yksvaan Jun 22 '26
Well don't use hardcoded keys, why this should even be a thing...
7
u/farzad_meow Jun 22 '26
umm you are supposed to pull keys from a vault or env var. it should never be hardcoded for any purpose
5
u/ngqhoangtrung Jun 22 '26
gitleaks, but ffs, this has never been an issue
5
u/Additional-Grade3221 Jun 22 '26
So glad I came from the before times hahah holy shit man
4
u/wewerecreaturres Jun 22 '26
Since you’ll probably keep using hardcoded keys…add betterleaks to your CI pipeline as a required check
1
u/everyoneisadj Jun 22 '26
Shouldn’t even let the AI see the key, your env, etc. this just comes down to lazy environment set up and prompting.
3
u/smokedfishfriday Jun 22 '26
lol what?!?
3
u/FleMo93 Jun 22 '26
Not AI is responsible for the code. The dev who approved the AI code is responsible. Hold the accountable. I have the same problem not only with devs but also with our POs. Everytime they mention "AI did write it" reply "you approved it".
2
u/Wiltix Jun 22 '26
Is this really a difficult problem to solve? Ultimately take it out of the developers hands and run the check on any PRs.
Make sure you have processes in place to review pipelines for new products before release, so a lazy dev can’t meet accidentally forget to review the ai generated code, they can’t accidentally forget to add the pipeline job to their builds or accidentally forget to enable PR only commits to the main / develop branch.
2
u/urkento Jun 22 '26
Ppl here have never worked with multiple people. Api key leaks from hard coded debug or poc, it does happen, like any other bug or sec issues, it will happen.
You have plenty solutions for it, git leaks, pr reviews, ci steps, git hooks etc...
Yes now it's easier than ever, but don't be condescending lol, 10y ago ppl were committing db uris, today too.
1
u/PaySilent7236 Jun 22 '26
We've had similar issues with hardcoded keys slipping through, using pre-commit hooks helps significantly.
1
u/Conscious-Process155 Jun 22 '26
Two words: code review. Also commiting code a dev haven't even seen is a recipe for disaster.
1
u/rid999 Jun 22 '26
For catching the hardcoded keys: a secrets scanner pre-commit hook on the developer's machine and a CI secrets scanner run before it becomes public, in case the developer somehow skips it. For catching keys that are correctly stored and ignored but still leak to the frontend via usage, you'll need a scanner that's a lot more capable than TruffleHog and Gitleaks.
1
u/BlazingThunder30 Jun 22 '26
Skill issue. I don't have anything else to offer.
0
u/SiOD Jun 22 '26
A server pre-receive hook is your enforcement, pre-commit hook is what Devs need to be installing themselves.