Secure Coding with AI

A guided, one-scene-at-a-time walkthrough

OwnEverything it reads is inputDeveloperapproves or auto-acceptsAI agentruns with your permissionsUntrusted inputissues · PRs · docs · webAlso in play: MCP · rules files · CI agents · providerA compromised agent is a compromised workstation.1 · Threat modelA name that doesn’t exist yetAI suggestsa package that isn’t realAttacker registersthat exact namenpm installmalware runsCheck age, downloads, maintainers firstAllowlist packages. Block brand-new ones.2 · Hallucinated packagesOld training, new CVEsOld trainingmodel misses new CVEsOld versionsuggested and mergedKnown CVEships to productionAudit every AI-made dependency listnpm audit · pip-audit · govulncheck · pin versions3 · Outdated dependenciesText can be a commandIssue or READMEhidden instructionsAgent reads ittreats text as ordersAttacker steersedits, leaks, fetchesRepo content is untrusted inputRestrict egress. Restart a compromised session.4 · Prompt injectionTools are part of the promptMCP servermalicious, or changed laterTool descriptionhidden instructionsSecrets leakthrough tool argumentsAllowlist servers. Diff tool definitions.Least privilege: a coding agent needs no email or payments.5 · MCP and toolsAuto-accept holds your keysAuto-acceptno confirmation promptsYour credentialsSSH keys · cloud tokensBlast radiusyour whole workstationRun in a container. Block egress.Ephemeral credentials. Fail-closed pre-execution hooks.6 · SandboxingInstructions that persistEdited rules fileCLAUDE.md · AGENTS.mdMerged quietlyit looks like plain textEvery run steereda persistent attackReview rules files like CI configAgents must not edit their own rules.7 · Rules filesThe diff you didn’t readYou reviewthe bug fixAgent also editslockfile · CI · testsHidden changeships unnoticedReview every file in the diffCODEOWNERS for CI, Dockerfiles, rules files.8 · Out-of-scope editsGreen is not correctTests failthe agent wants greenDelete or weakenequals becomes not-nullGreen CIbroken securityHumans review every test changeAdd adversarial tests the AI didn’t write.9 · Fake testsYour code leaves the buildingOpen filesenv files · keys · terminalProvider APIcontext is sent outSecrets + IPexposedExclude secrets from AI contextgitignore does not stop AI tools. Use vaults.10 · Context leakageScripts that run themselvesAgent editspostinstall · workflowsRuns by itselfbuild, install, deployPipeline ownedwith elevated accessScrutinize auto-running filesPin GitHub Actions to a commit SHA.11 · Build supply chainA bot with the keysMalicious PRattacker-written textCI agent reads itand holds org secretsConfused deputysecrets leakGive CI agents minimum permissionsIsolate runners. Approve pushes and workflow edits.12 · CI confused deputyInvisible textHidden charactersbidi · zero-widthReviewer seesclean-looking textAgent obeyswhat you can’t seeScan for U+202A–202E and U+200BSanitize Markdown images and links in output.13 · Unicode tricksCompromise travelsAgent Ais compromisedOutput passed onAgent B trusts itInjection spreadsacross agentsAgent output is untrusted inputContext boundaries. Scoped sub-agent permissions.14 · Multi-agentA human owns itAI writesthe changeHuman reviewsand approvesHuman ownsthe risk“The AI wrote it” is not an excuseKeep an audit trail: who approved, which tool and model.15 · AccountabilityVerify · Contain · OwnVerifypackages · CVEs · diffs · testsContainsandbox · egress · least privilegea human approves every changeTreat everything the agent reads as untrustedReassess as agent capabilities change.16 · Recap

Use Previous / Next (or the arrow keys) to step through all 16 scenes, or Auto-play for a hands-free presentation.