Skip to content
engineering workbench.by StudyPort Academy
Learning path
Advanced18 min

Secrets management in depth

Understand the idea

A key in the repository is already copied. The process should receive it when it starts.

The idea

Environment and secrets is the rule that the handler reads a variable instead of a literal. This lesson is what happens around that line. A key, a database URL, or a private signing key that was committed is in the history. Removing the line in a later commit does not remove the blobs people already fetched. The scan in the run is the pre-commit check: a file that contains sk- or a mongodb+srv URL is blocked, and a file that only mentions process.env.AI_API_KEY is clean. The value itself is injected when the process starts, by the host, not by the repository. Rotate any key that did land in a commit. Do not print the value in a log while you are rotating it. The signing key and the password-hash pepper, if you use one, are in this category. The user's password is not a secret you inject. It is a hash you store.

What changes

Where a secret can sit
PlaceWho can read itWhat you do
A commitEveryone with the history, foreverDo not commit it. Rotate it if you did.
A pre-commit scanThe hook, before the commit existsBlock sk- and connection strings
The process environmentThat process, at runtimeInject it at start. The source only names the variable.

The command

Block a literal key, allow an environment name

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

The literal sk- line is blocked. The process.env line is clean. The last line is the reminder that the value shows up at startup.

Guided challenge

Block the literal key

scan currently ignores sk- and only catches a database URL. Return blocked when the text contains sk- as well.

Block the literal key

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

blocked
clean

Hints 0/2

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01When is a committed key exposed?
    02Where should the process read the key?

    Ready to call this one understood?

    Mark this lesson complete to earn 200 XP. You can always revisit it.

    Sign in to save progress
    Next lesson