
AI coding assistants have gone from novelty to default in a remarkably short time. Developers now accept autocomplete suggestions, generate entire functions from a comment, and paste in package install commands without a second thought. That convenience carries a cost that most teams have not yet priced in. Every suggested import, every npm package, every pip install is a dependency decision, and many of those decisions are being made by a model that has no idea whether the package it just recommended was published last week by a legitimate maintainer or registered yesterday by someone waiting for a typo.
The surprising part is how ordinary the failure mode is. Researchers have documented cases where large language models invented package names that did not exist, and attackers quickly learned to register those names on public registries and fill them with malicious code. The term for this is "package hallucination," and it turns a harmless-looking mistake into an entry point. A developer who trusts the suggestion and runs the install has just executed someone else's code inside their build environment, sometimes with access to deployment credentials sitting in environment variables.
This article walks through the real AI coding tools security risks that matter for shipping software, not the abstract ones. We will cover how supply-chain attacks reach your repository through AI suggestions, what to verify before any dependency lands in production, how to compare the protections different tools and workflows offer, and a repeatable checklist you can apply this week. The goal is a practical review process that catches problems at the point where they are cheap to fix.
Key Takeaways
- AI assistants can recommend packages that do not exist, and attackers can register those names. Treat every new dependency as untrusted until verified.
- Verify a package's publisher, age, download history, and repository link before adding it, regardless of who suggested it.
- Never let generated code run with production secrets in scope. Keep credentials out of local and CI environments that process AI-generated changes.
- Pin versions and commit lockfiles so that a suggested "latest" install cannot silently change what you ship.
- Run dependency scanning and secret scanning on every pull request, including those that were mostly written by an assistant.
- Human review of AI-generated diffs should focus on new imports, network calls, file system access, and anything touching authentication.
What Are AI Coding Tools Security Risks, Exactly?
The phrase covers several distinct problems that often get lumped together. Separating them makes each one easier to defend against.
- Hallucinated dependencies. The model suggests a package or module name that is plausible but nonexistent. If an attacker has published a package under that name, your install pulls their code.
- Insecure code patterns. The model reproduces common but vulnerable patterns: string-concatenated SQL, disabled TLS verification, hardcoded keys, or weak randomness for tokens. These are learned from public code that was itself often insecure.
- Training and context leakage. Prompts can carry proprietary code, internal hostnames, or secrets into a vendor's systems, depending on the tool's data retention and training settings.
- Poisoned suggestions. Malicious content in a repository, README, or issue can influence what an assistant recommends when it reads that context, a form of prompt injection.
- Overtrust and reduced review. Developers review AI-generated code less rigorously than their own, which lets ordinary bugs and malicious additions pass through.
Of these, the supply-chain problem is the one with the most dramatic blast radius, because a single bad dependency can run code on every developer laptop and every CI runner that installs it.
How Does a Supply-Chain Attack Reach Your Code Through an AI Suggestion?
Consider a realistic sequence. A developer is building a small data-export feature and asks an assistant how to parse a specific file format. The assistant replies with a helpful snippet that imports a module called something like fast-xlsx-stream and suggests npm install fast-xlsx-stream. The name sounds reasonable. The developer has never heard of it, but the snippet looks right, so they install it.
Now suppose the real library is named differently, and fast-xlsx-stream was registered two days ago by an account with no history. Its install script runs a postinstall hook that reads ~/.npmrc and environment variables, then posts them to an external server. The developer's local npm token, and in some setups their cloud credentials, are gone before they ever run the code. If the same snippet made it into a CI pipeline, the leak happens on the runner, where deployment keys are often present.
Nothing in that chain required a sophisticated exploit. It required a plausible name, a trusted-looking suggestion, and an install command run without verification. That is why the defenses below focus on the moment a dependency enters the project.
What Should You Check Before Any New Dependency Ships?
Apply these checks to every package an assistant suggests, and to every package a human adds. Treat the assistant's confidence as irrelevant to the verification step.
- Confirm the package exists on the official registry under that exact name. Search the registry (npm, PyPI, RubyGems, crates.io, and so on) and check for a close match. If the name returns nothing, or the results are a single brand-new package, stop.
- Check the publisher. Look at the maintainer accounts, how many packages they publish, and whether the account has history beyond the package in question.
- Check the age and release history. A package first published a few days ago with a version bump and a large download count is worth investigating. Real packages accumulate history gradually.
- Verify the linked source repository. The package should link to a public repository whose contents match the published code. Mismatches are a red flag.
- Inspect install scripts. Look for
postinstall,preinstall,setup.pyexecution, or equivalent hooks. Install scripts are where most credential theft happens. - Check for an existing alternative. If the function is common, the standard library or a well-known package probably already covers it. Prefer those.
- Pin the version and commit the lockfile. This prevents a later "latest" resolution from swapping in something different.
Teams that run this checklist as a habit catch most hallucinated and typosquatted packages before they touch a shared environment. It takes a few minutes per dependency and saves a very expensive afternoon later.
A worked example: auditing a dependency list
Say your project has 47 direct and transitive dependencies flagged for review after a sprint where the team leaned heavily on an assistant. You cannot manually verify all 47 every week, so triage them. Sort the list into three groups.
- Group A, well-established (roughly 30 packages). Maintained for years, large download counts, known maintainers. Confirm the version is pinned and move on.
- Group B, moderate (roughly 12 packages). Real and used, but smaller or newer. Check the repository link, the install scripts, and the release history. Budget about five minutes each, so roughly an hour.
- Group C, suspicious (roughly 5 packages). Published recently, low downloads, unclear maintainer, or a name that resembles a popular package. Remove them unless a human can justify the need. Replace with a vetted alternative.
In practice, that triage surfaces the handful of packages that deserve scrutiny without turning the audit into a week-long project. If Group C contains anything, check your CI logs and developer machines for unexpected outbound connections from the install step.
Which Protections Do Common Setups Actually Provide?
No single control solves the problem. Compare the options by what they block and what they leave open.
| Approach | Catches hallucinated names | Blocks malicious install scripts | Protects secrets in CI | Setup effort | Ongoing cost |
|---|---|---|---|---|---|
| Manual verification only | Yes, if disciplined | Only if you read the scripts | No | Low | High human time |
| Lockfiles and pinned versions | No (locks what you already accepted) | No | No | Low | Low |
| Automated dependency scanning in CI | Partly (known-bad packages) | Partly | No | Medium | Low to medium |
| Install scripts disabled by default | No | Yes | Yes, indirectly | Low to medium | Low, but occasional breakage |
| Scoped, short-lived CI credentials | No | No | Yes, strongly | Medium to high | Medium |
My own view is that the highest-value combination for a small team is lockfiles, install-script restrictions, and short-lived scoped credentials. Scanning catches what is already known to be bad, but the hallucinated-package case is by definition new, so scanners often miss it. Limiting what a malicious install can reach matters more than identifying it perfectly.
How Do You Keep Secrets Out of AI-Assisted Workflows?
Secrets exposure is the second half of the risk, and it is largely within your control. Work through these steps.
- Inventory where secrets live. Check
.envfiles, shell profiles,~/.npmrc, cloud CLI config, and CI variables. Most teams are surprised by the count. - Remove production credentials from developer laptops. Developers rarely need live deployment keys. Use staging credentials or short-lived access granted on demand.
- Scope CI credentials per job. A job that runs tests should not have permission to deploy. Split the pipeline so that the stage processing untrusted dependencies has no deploy rights.
- Enable secret scanning on pull requests. Assistants sometimes echo a key from a config file into generated code. Catch it before merge.
- Review your tool's data settings. Check whether prompts and code snippets are retained or used for training, and whether an enterprise tier offers stricter terms. Do not paste credentials or customer data into a prompt.
- Rotate anything that may have been exposed. If a suspicious package ran on a machine, treat every token that machine could read as compromised.
Password hygiene matters here too. If a developer's local credential store is compromised, the attacker inherits access to everything it unlocks. Our guide on password manager vendor breaches and what to rotate covers how to think about that exposure
Cover image: Sad Cartoon versus Technology by Sean Loyless, licensed under BY 2.0 via Openverse.








