Day 4 of 1060 minShell WalkerHands-on lab
Day 4: Secrets in the Context Window
Taught by Mr Elite Updated
By the end of today you can
- Explain what a context window is and where its contents can end up
- Spot secrets in .env files, logs, configs and stack traces before pasting
- Redact a prompt so it keeps its debugging value without the secrets
- Set up an ignore file and a pre-paste habit for your assistant
Warm-up
Answer from memory first, then tap to check. Recalling yesterday is what makes it stick.
What is the primary fix for SQL injection in generated code?
Parameterised queries, so user input stays as data and never becomes part of the SQL text.
Why should you prove a flaw with an attack input rather than only reading the code?
Reading can miss how the code really behaves. A working attack input shows the flaw is real, and the same input becomes a regression test.
You have a bug. The app crashes on startup, the stack trace is forty lines long, and you want the assistant to tell you why. So you select everything in the terminal, copy it and paste it into the chat. It takes four seconds.
Somewhere in those forty lines is a database connection string with a live password in it. You did not read it. You did not mean to share it. Yesterday we reviewed what the assistant writes. Today we review what you send it, because the input side leaks just as easily as the output side.
Review the input as well as the output
On day 3 we treated generated code as untrusted and checked it before it went anywhere near production. The same discipline applies in the other direction. Anything you paste or let an agent read leaves your machine and lands in a system you do not control.
So the habit for today is simple. Before you send anything, ask what is in it that I would not put on a public page. If you cannot answer, you have not read it yet. Reading means every line, not a glance at the top and bottom.
This matters because debugging pastes are rushed. You are annoyed, you want an answer, and the text looks like noise. That is exactly the state in which a password slips through, so we build a routine that works even when you are tired.
- Context window
- Everything the model can see in one conversation: your prompts, pasted text, files an agent reads, and its earlier replies.
- Secret
- Any value that grants access: passwords, API keys, tokens, private keys, session cookies, connection strings.
- Redaction
- Replacing a sensitive value with a harmless placeholder so the text stays useful but the secret is gone.
Where the context window lives
A context window is not just a clever memory in the model. It is data sent over the network to a provider, and providers handle it in different ways. Depending on the service and your plan, it may be kept in chat history, written to logs, reviewed by staff for abuse, or used for training.
You also have local copies. Chat history in your browser, session files from a coding agent, and editor extension caches all keep what you sent. A secret pasted once can exist in several places, and you cannot recall it from any of them.
Take five minutes at some point to open the settings of the assistant you use and read what it says about history and training. Policies change and differ between free and paid plans, so check yours rather than trusting a memory of it.
Quick check
You pasted a log containing an API key into a chatbot, then deleted the conversation straight away. What should you do?
You cannot confirm every copy is gone, so the safe response is to revoke the key and issue a new one.
The usual suspects
Secrets rarely arrive labelled. They hide in material that looks like harmless debugging output. These are the places I check first.
- .env files
- Plain text KEY=value files holding database URLs, API keys and signing secrets.
- Logs
- Request logs often include Authorization headers, cookies and tokens in query strings.
- Config files
- YAML, JSON and settings files with embedded credentials, plus cloud config in your home folder.
- Stack traces
- Errors that print connection strings, file paths with usernames, internal hostnames and sometimes request bodies.
Look for telltale shapes. Long random strings, prefixes like sk_, ghp_ or AKIA, the word Bearer, URLs in the form user:password@host, and anything after words like password, secret, token or key.
postgres://app:S3cretPw@db.internal:5432/shop
Authorization: Bearer eyJhbGciOi...
GET /export?api_key=abc123def456
AWS_ACCESS_KEY_ID=AKIA................Notice that two of these have no obvious label. The connection string hides a password between two punctuation marks, and the query string hides a key inside a URL. These are the ones people miss.
Watch me do it: find and redact
I will build a fake project with fake secrets, scan it, and produce a safe prompt. Everything here runs on your own machine and every credential is invented. Use a Linux, macOS or WSL terminal. The commands work the same on all three for what we do.
mkdir redact-demo && cd redact-demo
printf 'DB_URL=postgres://app:Hunter2pass@db.internal:5432/shopnSTRIPE_KEY=sk_test_FAKE1234567890abcdefnJWT_SECRET=not-a-real-secret-valuen' > .env
cat .envprintf 'ERROR connect failed: postgres://app:Hunter2pass@db.internal:5432/shopnGET /api/orders Authorization: Bearer eyJFAKE.TOKEN.valuenat /home/sam/shop/db.js:14n' > error.log
cat error.loggrep -nEi 'password|secret|token|key|bearer|://[^ ]+:[^ ]+@' .env error.log.env:1:DB_URL=postgres://app:Hunter2pass@db.internal:5432/shop
.env:2:STRIPE_KEY=sk_test_FAKE1234567890abcdef
.env:3:JWT_SECRET=not-a-real-secret-value
error.log:1:ERROR connect failed: postgres://app:Hunter2pass@db.internal:5432/shop
error.log:2:GET /api/orders Authorization: Bearer eyJFAKE.TOKEN.valueLook at what grep did not flag. The path /home/sam/shop/db.js has no secret word in it, yet the username sam is personal detail you may not want to share. A scanner only finds what you taught it to find, so keep reading with your own eyes.
sed -E 's#://[^:]+:[^@]+@#://USER:REDACTED@#; s#Bearer [A-Za-z0-9._-]+#Bearer REDACTED#; s#/home/[^/]+#/home/USER#' error.log > error.clean.log
cat error.clean.logERROR connect failed: postgres://USER:REDACTED@db.internal:5432/shop
GET /api/orders Authorization: Bearer REDACTED
at /home/USER/shop/db.js:14Notice that the cleaned log still says what failed and where. That is the goal. The assistant needs the shape of the problem, not the live values. For the .env file, the better answer is usually not to paste it at all. If the assistant needs to know a variable exists, say so in words, such as DB_URL is a Postgres URL.
grep -nEi 'password|secret|token|key|bearer|://[^ ]+:[^ ]+@' error.clean.logRead those two lines. Line 1 now says USER:REDACTED@ and line 2 says Bearer REDACTED. Both match the pattern but hold no real value, so they are fine. If you ever see a long random string in this output, that line needs another pass.
Ignore files and standing habits
Manual redaction fixes one paste. Agents read files on their own, so you also need standing rules. Many assistants support an ignore file that lists paths they must not read or index. Names differ by tool, such as .cursorignore or similar settings, so check your tool's documentation for the exact file name and syntax.
.env
.env.*
*.pem
*.key
secrets/
*.log
.aws/To try it in your demo folder, create the file with the list above, using the name your tool documents. Then run cat on it and check that all seven lines are there. Check also that each pattern matches something real, such as .env and error.log in your folder. A pattern that matches nothing protects nothing.
Beyond ignore files, three habits do most of the work. Keep real secrets out of the project folder where you can. Use fake values in dev and test configs. And paste the smallest slice that reproduces the bug, not the whole file.
Quick check
Which prompt is safest to send while still useful for debugging?
A placeholder keeps the structure for debugging while removing the value, and partial keys are still leaks.
Practice in the lab
Now do it on a realistic paste. The lab gives you a stack trace, a config snippet and some logs, and asks you to redact every secret before the paste goes out. Open it from the lab panel for today.
Work the way we did in the demo. Read everything once without editing, list what grants access, then redact. Check for repeats of the same secret in other places. When you finish, read the result top to bottom as if you were the person receiving it, and ask whether any line would let you into something.
Your turn
Secrets in the Context Window
This lab puts you in the position of a developer about to paste material into a public chatbot. It tests whether you can read carefully under realistic conditions, where secrets sit among ordinary debugging text.
What to try
What to notice
- How many secrets were not labelled as secrets at all
- How a single missed repeat undoes your careful work
- How much debugging value survives after redaction
If it did not work
Redacting the labelled password but missing the token in a header or URL
Scan for shapes as well as words: Bearer, user:pass@host, long random strings and known key prefixes.
Pasting the whole file because trimming takes effort
Paste the smallest slice that reproduces the problem. Less text means fewer chances to leak.
Partly masking a key, such as keeping the first and last characters
Replace the whole value with a placeholder. Partial keys can still help an attacker.
Deleting the chat and assuming the secret is safe
Rotate the credential. Treat anything pasted as exposed.
Recap
- The context window is data sent to a third party, and copies may persist in several places.
- Review what you send in, just as you review what comes out.
- Secrets hide in .env files, logs, configs and stack traces, often unlabelled.
- Replace values with placeholders so the text stays useful for debugging.
- Ignore files stop agents reading sensitive paths, but they supplement your own review.
- If a secret was pasted, rotate it.
Cheat sheet
grep -nEi 'password|secret|token|key|bearer' file- Find secret-shaped lines with line numbers
sed -E 's#pattern#REDACTED#' file- Write a copy with matches replaced
user:pass@host- Credentials embedded in a URL
Bearer <token>- Auth header value that must be redacted
Ignore file- List of paths the assistant must not read
Rotate- Revoke the old secret and issue a new one
Before the next day
Mission: Prompt redaction pack
Build a small kit you can reuse every time you ask an assistant for help. You will practise on invented data only, so nothing real is at risk, and you will leave with a checklist you can actually follow.
About 30 min
You are done when: A folder containing the fake .env, redaction-checklist.md, before-after.md showing the prompt before and after, and your assistant's ignore file.
Want more? Write a small shell script that runs your grep scan and exits with an error if any secret-shaped text is found in a file you pass it.
Quiz
4 questions. Your score is saved with your progress.
1. Why does deleting a chat not fully undo pasting a secret?
You cannot verify every place the data was stored, so rotation is the reliable response.
2. Which line in a stack trace is the biggest concern?
It embeds a username and password in a connection string, giving direct access to the database.
3. What does good redaction preserve?
Placeholders keep the text useful while removing anything that grants access.
4. What is the main limit of an assistant's ignore file?
Ignore files control what the tool reads automatically, not what you paste or what sits in unlisted places.
Finish the day
Mark the day complete to save your progress.
Next: On day 5 we look at what the assistant suggests you install. You have checked what goes in and what comes out, and next we check the packages it recommends, including ones that do not exist.
Your notes
Private to this device. Write what you want to remember from today.