Coding with AI Assistants · Risks and Team Practices
Secrets, Private Code and Licences
What you paste into an assistant may leave your machine; keep secrets out, follow your company's rules, and mind licences.
The problem
A developer pastes a failing config file into an AI chat to ask for help. It contains the production database password. Another developer copies a large function an assistant produced, which closely matches code from a project under a licence your company does not allow.
Real-world analogy
You would not read your bank PIN aloud to a helpful stranger, even if they are fixing your card reader. Share the problem, not the secret.
The idea
- Know the rules: your company's policy on which AI tools are approved and what code or data may be shared with them, and the tool's data settings (retention, training use).
- Never paste secrets: keys, passwords, tokens, customer data. Replace them with placeholders before sharing.
- Scan before sharing and before committing: secret scanners catch keys in files and diffs.
- Licences: be careful with long, distinctive generated code; some tools offer filters that block suggestions matching public code. When in doubt, check and attribute.
- Rotate immediately if a secret was exposed; deleting the message is not enough.
The code
A small pre-share scanner that replaces likely secrets with placeholders:
import re
RULES = [
(r"(?i)(password|passwd|secret|token)\s*[:=]\s*\S+", r"\1=<REDACTED>"),
(r"postgres(?:ql)?://([^:\s]+):[^@\s]+@", r"postgresql://\1:<REDACTED>@"),
(r"\bAKIA[0-9A-Z]{16}\b", "<AWS_ACCESS_KEY_ID>"),
]
def mask(text):
count = 0
for pattern, replacement in RULES:
text, n = re.subn(pattern, replacement, text)
count += n
return text, count
config = ("DATABASE_URL=postgresql://app:[email protected]:5432/shop\n"
"AWS_KEY=AKIAIOSFODNN7EXAMPLE\n"
"DEBUG=false\n"
"api_token: tok_9f8e7d6c5b4a")
masked, found = mask(config)
print(masked)
print("secrets masked:", found)
Output
DATABASE_URL=postgresql://app:<REDACTED>@db.internal:5432/shop AWS_KEY=<AWS_ACCESS_KEY_ID> DEBUG=false api_token=<REDACTED> secrets masked: 3
Common mistakes
- Pasting full config files or logs that include credentials or customer data.
- Assuming a deleted chat message removes the exposure.
- Using unapproved AI tools with company code.
- Copying long generated code without considering licences.
Key points
- Follow your company's AI tool policy and know each tool's data settings.
- Never share secrets or customer data; mask before sharing and scan before committing.
- Rotate exposed secrets immediately, and be careful with licences.
Further reading: OWASP secrets management cheat sheet · Gitleaks secret scanner · Choose a license: licence overview
Practice questions
What should you do if you accidentally pasted a secret into an AI tool?
Answer
Treat it as exposed: rotate or revoke the secret immediately and follow your incident process; deleting the message does not undo the exposure.
How can teams prevent secrets reaching AI tools and repositories?
Answer
Mask files before sharing, use secret scanners in pre-commit hooks and CI, keep secrets in a secrets manager rather than files, and set clear policies on approved tools.
Why consider licences when using generated code?
Answer
Long, distinctive generated code may closely match existing open-source code whose licence imposes obligations; check, use matching filters where available, and attribute when required.
Open in the app to mark lessons complete, take notes and track your progress.