Skip to content
Minute Campus.

Almost rightLesson 081 min

The password is in the code

A program has its API key typed straight into the file. It runs perfectly, so nothing signals a problem, but code gets shared, and the key travels with it. The fix is to read the key from the environment. The real value stays on the machine that runs the code, and the program stops with a clear error if it is missing.

Remember

Code says what to do; a secret says who you are. Keep them apart.

Transcript

The lesson, word for word.

Read it at your own pace, or search the page for a term.

The password is in the code. Three seconds: which line? Line three. The program needs a key to call a paid service, and the key is typed straight into the file, between quote marks. It runs perfectly. That is the trouble: nothing tells you it is wrong. But code gets shared. It is pushed to a repository, pasted into a chat, shown on a screen in a meeting. Everywhere the code goes, the key goes too. And if you ask an AI assistant to make something work quickly, pasting the key in is the shortest path. The fix: the code only says, read the key from the environment. The real value lives outside the file, on the machine that runs it. If the key is missing, the program stops with a clear error. The rule: code says what to do. A secret says who you are. Never keep them in the same place.

Questions? Comment on the lesson on YouTube

New lessons every day.

Follow Minute Campus where you already scroll.