Most of what follows arrives in a script for the same reason: it was the quickest way to make something work. That is a perfectly understandable motivation and it produces a small number of problems that are genuinely expensive to unwind.
What is the main one?
Credentials. Passwords, API keys, tokens and connection strings typed directly into a script. They work immediately, which is the appeal, and they then travel everywhere the script goes: into copies, into screenshots, into anything you paste for help, and into version control where they remain in the history after being deleted.
Where should credentials go?
In an environment variable or a separate file that is excluded from sharing. Both are a few lines of setup and both remove the problem entirely.
Rewrite this so the key is read from an environment variable rather than written in the code. Show me how to set the variable on my system, and how to make sure the file holding it is never shared.
What happens if a key does get exposed?
Rotate it, which means generating a new one and invalidating the old. Deleting the line is not sufficient, since the old value is still valid and may already be in a copy somewhere.
Providers make this straightforward and people delay it out of embarrassment, which is the wrong response by some margin.
What else should stay out?
- Personal data. Real names, addresses and records used as test data.
- Internal addresses. Server names and paths that reveal how a system is arranged.
- Absolute paths with your name in them. Harmless and awkward when shared.
- Commented-out old code. Which accumulates and confuses.
- Sample data from a real export. Which frequently contains real customers.
Why is real data as test data a problem?
Because it ends up in the same places as everything else, and a folder of test files taken from a genuine export contains information about identifiable people that nobody agreed to circulate.
Generating fake data for testing takes a minute and removes the question.
What about pasting code for help?
Read it before pasting, every time. This is the most common exposure route now, since the natural thing to do when something breaks is to paste the whole file, and the whole file may include the key three lines from the top.
Is any of this different for a personal project?
Slightly, and less than people assume. A key in a personal script still grants access to your account and still costs money if somebody finds it, and personal projects have a way of becoming shared or published later.
What is the habit worth forming?
Never type a credential into a file. If you have done it once you will do it again, and the arrangement where secrets live outside the code costs five minutes to set up and applies to everything you write afterwards.