What you type leaves your machine
Using an AI assistant safely means knowing two things. Your request and your code are sent to a model, and the code it sends back can contain security faults. It matters because a password pasted into a prompt cannot be taken back.
A developer pastes a whole config file to ask about one setting. The file also held a database password.
By the end of this lesson
Note
I can name what not to paste into an assistant and what generated code gets wrong.
Key words
| Word | What it means |
|---|---|
| Secret | a password, key or token that proves who you are |
| Personal data | facts about a real person |
| Placeholder | a made-up value that stands in for a real one |
| Injection | input that is treated as code |
| Rotate | to replace a secret with a new one |
The cells students fill in are left blank in this preview.
Four things never to paste into a prompt
Do not paste secrets: passwords, keys and tokens. Do not paste personal data, such as names, emails or grades of real people. Do not paste code you have no right to share.
And do not paste anything your employer or college has said must stay private. Ask first when you are not sure.
Worked example: what to do instead
| Do not paste | Why | Paste this instead |
|---|---|---|
| A real API key | It could be used by anyone who sees it | The word API_KEY as a placeholder |
| A list of student names and marks | It is personal data about real people | Three invented rows with the same shape |
| A whole config file | It may hold more than the one setting | Only the lines you ask about, cleaned |
| A customer's email | It identifies a person | [email protected] |
The cells students fill in are left blank in this preview.
Search made-up text for a key line
docker exec agent sh -c "printf 'user=ada\nAPI_KEY=abc12345\n' | grep -n KEY"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A search can catch a secret
The command made up two lines of text and searched them for the word KEY. It printed 2:API_KEY=abc12345: the line number, a colon and the line.
The value here is invented. A real check, the one you write in the assignment, looks for several signs at once. It is a safety net, not a guarantee.
A common mistake
Warning
Many people think they can undo a pasted secret by deleting it in the next message. Once sent, it has left your machine. Treat it as exposed: rotate it, which means replacing it with a new one, and tell whoever owns it.
See what the lab's assistant must ask first
docker exec agent grep -o '"permission".*' /home/node/.config/opencode/opencode.jsonShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
The assistant asks before it edits or runs
The line above is the lab's own setting. It says the assistant asks before it edits a file, asks before it runs a command and is refused any web fetch.
Those questions are your chance to review. Read what it wants to do before you say yes. A yes you did not read is the same as a paste you did not check.
Generated code repeats common security faults
A model learned from a great deal of public code, and much of it is insecure. So its code can build a database query by joining text. It can put a password into the source. It can trust input without checking it.
The first one is called injection. Read the two functions below. Neither is run in this lesson.
Two ways to ask a database
def find_member(db, name):
# Risky: the name is glued into the query text.
return db.execute("SELECT * FROM members WHERE name = '" + name + "'")
def find_member_safely(db, name):
# Safer: the name travels apart from the query.
return db.execute("SELECT * FROM members WHERE name = ?", (name,))
Worked example: faults in generated code
| Fault | What it looks like | The safer way |
|---|---|---|
| Injection | Input joined into a query with + | Pass the input as a separate parameter |
| Hard-coded secret | password = "..." in the source | Read it from the environment |
| Unchecked input | Using a value before testing it | Check type, length and range first |
| Invented package | An import of a name that does not exist | Check the package is real and trusted |
The cells students fill in are left blank in this preview.