r/github • u/GALACTIC_HER0 • Apr 11 '26
Question Canon event, pushed .env
beginner, but pushed .env, contained mongodb,stream api secret and clerk api.
just a beginner working on a portfolio project, had this accidentally when working on first project too, nothin happened then, should I be worried now?
3
u/steviejackson94 Apr 11 '26
Private repo?
9
u/GALACTIC_HER0 Apr 11 '26
public
6
u/geferon Apr 11 '26
rotate credentials, try and modify the history to remove it, but it will still be there and bots have very likely already gotten it, make sure it doesn't happen again by adding .env* to .gitignore
8
143
u/wasnt_in_the_hot_tub Apr 11 '26
Rotate the credentials that were in the env file
42
u/Kirides Apr 11 '26
Rotated them using ROT13, am I safe now?
29
u/SheriffRoscoe Apr 11 '26
Better do it again, for extra security.
4
u/grufkork Apr 12 '26
ROT26? I’m guessing that’s kind of like going from SHA-1 to SHA-256
2
2
u/wasnt_in_the_hot_tub Apr 12 '26
ROT13 to ROT3328 would be like going from 1 to 256, because numbers
57
u/1_Yui Apr 11 '26
There are bots that automatically scan repos for leaked secrets and keys. Even if you don't believe anyone saw it, please just be safe and replace the affected credentials.
9
u/chrisalbo Apr 11 '26
We have all done this. For me it was just two days ago. Pushed a key to private GitHub rep. The key was in a dev environment but once it’s pushed, there is no option but to invalidate the key.
8
2
u/ToTheBatmobileGuy Apr 12 '26
Interesting... push rulesets are only available for organizations (aka paid enterprise/teams and open source orgs) and only apply to repos under that organization.
It would be nice if GitHub had a per-user push ruleset that defaults to preventing pushing of certain file patterns.
1
u/Original-Group2642 Apr 12 '26
Create a global ignore file at ~/.config/git/ignore add .env and similar. I also have *.local.* in mine so anything like settings.local.json also gets ignored.
Then run git config --global core.excludesFile ~/.config/git/ignore to add the file to your global git config.
You should still add the files to your local .gitignore files, but the global ignore file should help prevent the likes of .env getting committed by accident should you forget.
1
u/rudytubes Apr 13 '26
Had the same happen to too, lol. Thank god it was just some MongoDB credentials tho. I believe git guardian should have alerted and removed it for you tho.
1
-1
u/8bitAlexx Apr 12 '26
vibecheckme.dev would help prevent things like that. It’s a predefined prompt to help mentor and prevent rookie mistakes.
-1
9
64
u/serverhorror Apr 11 '26
Regardless of "private" or "public", the only sane actions:
Add the
.envfile to your.gitigniregit rm --force .env- remove the file from the repoCommit and push that change to the repo
Rotate all the credentials and secrets that were committed
If you have GitHub actions, use (at least) GitHub Secrets to make sure that the actions can still access the required information
Consider the credentials compromised, even if nothing happened yet!