Security and Supply Chain in AI-Assisted Code
An assistant will name a package that does not exist, read files it should never see and repeat insecure patterns with confidence. None of this needs a new security program. It needs five daily controls on dependencies, secrets and tool permissions, each with an owner and a number a manager can check.
After this chapter you can
- Name the three ways an assistant changes exposure: invented package names, leaked secrets and over-trusted output.
- Set a dependency rule combining an approved-package gate, human sign-off on new packages and a cooling period for fresh versions.
- Reduce secret exposure by keeping production credentials out of the tool's reach, scanning before push and shortening token life.
- Ask four review questions of generated code touching identity, input, cryptography or data.
- Explain why a local assistant inherits its user's access, and run it with prompts on or in a sandbox.
In December 2023 a security researcher, Bar Lanyado, noticed that code assistants kept suggesting the same command:
install a Python package called huggingface-cli. No such package existed. He registered the name on the public index
with an empty, harmless file inside and waited. In the three months that followed it was downloaded more than 15,000 times,
and a README in a research repository from Alibaba told readers to install it, as reported by The Register1. The package was empty by design, so the experiment itself shipped no malicious code. It showed how little stands between a
confident wrong answer and a program running on someone’s machine.
That is the question this chapter answers for you as a manager: what changes about security when an assistant writes part of the code? Not everything. Your existing application security program still applies, and the pipeline gates from the last chapter still run. What changes is where the code, the names and the credentials come from, and who looks at them before they take effect. Level 1 gave you the posture, which is containment rather than elimination, and a note that provenance and licensing need a record. Here the posture becomes five controls your team runs every day.
Three ways the assistant changes your exposure
Think of the assistant as a very fast colleague who has read a lot, remembers imperfectly, runs commands on request and sits on the same laptop as your credentials. Three exposures follow from that description.
The first is invented names. An assistant that writes an import or an install line produces a plausible name, whether or not the registry has it. If it does not, anyone can claim the name. The second is exposed secrets. Keys travel to the vendor in prompts and file context, get written into generated code and sit in the environment that the tool can read. The third is trusted output. Generated code arrives fluent and formatted, and people review it with less suspicion than they would give a stranger’s patch.
None of the three is hypothetical, and the evidence for each differs in strength. Take them in turn, then see how they combined in one real incident.
Invented names: the package that is not there
Spracklen and colleagues measured the first exposure at scale. They generated 576,000 code samples in Python and JavaScript from 16 code-generating models and checked each suggested package against the real registries. The share of suggestions that named a non-existent package averaged at least 5.2 percent for commercial models and 21.7 percent for open-source models, with 205,474 unique invented names across the study2. Read this with its scope. It tests the models of its time, in two languages, on prompts the authors chose. It does not tell you your team’s rate, and it does not show how often anyone installed an invented name. It does show that the event is common enough to plan for, and that the range between models is wide.
Lanyado’s case adds the human half: real people and a real organization installed or recommended a name that only a model had produced. Notice what did the damage there. Nothing was malicious in the package itself. The failure was a process in which a suggestion became an install with no check in between.
The control is a dependency rule with three parts:
- Resolve through a gate. Builds install only from an allowlist, or from a registry proxy that serves approved packages and refuses the rest. A name that is not on the list fails loudly in the developer’s terminal, which is a cheap place to learn about it.
- Make a new dependency a human decision. Someone named on the pull request confirms the package exists, who publishes it, whether its source repository matches, and whether the name sits one letter from a popular one. Keep this check short, and keep the path quick, or people will work around it.
- Cool new versions. Require a minimum age since publication before a version is installed. The Nx case below shows the reasoning.
Level 1’s note on provenance has a supply-chain edge too: record which assistant and which model were used for changes in regulated or licensed parts of the code, so an audit question about origin has an answer.
Case: the Nx compromise and the assistants on the laptop
On 26 August 2025, malicious versions of the Nx build tool and several plugins appeared on npm. The maintainers’ advisory
describes the chain. A GitHub Actions workflow contained a bash injection and ran with elevated pull_request_target permissions, which let the attacker
trigger the publishing workflow and capture the npm token it held. With that token the
attacker published eight versions of the nx package and plugin releases. Each carried a postinstall script that scanned the
file system for credentials and posted what it found to a repository under the victim’s own GitHub account. NPM removed the affected versions the same evening (about four hours after the first was published)3.
Trade press added a detail that matters for this chapter. According to The Hacker News, drawing on security-vendor research, the malware also tried to run any AI command-line assistant installed on the machine, using flags that skip permission prompts, and asked it to hunt for sensitive files. It reported 2,349 distinct secrets exposed, mostly GitHub tokens plus cloud and AI-provider keys4. The advisory itself does not describe the assistant behavior, so treat that part as press-reported.
Three lessons transfer to your team, each limited to what the sources show.
The first is about timing. The advisory records removal about four hours after the first malicious version appeared. A rule that holds new versions back for a few days is aimed at exactly that kind of window. That is an inference from one incident, not a measured result, and a cooling period does nothing against a package that is malicious from its first release. Use it as one layer.
The second is about scripts. The payload ran at install time. Turning off install scripts for packages the team has not reviewed removes that moment, at the price of some packages needing a manual step.
The third is about the machine. A local assistant inherits the reach of the person running it. If its permission prompts are off, any program that can start it has that reach too. This is the strongest argument for running assistants with prompts on, or inside a container or dev environment that holds only the project’s files.
Secrets: three exits and one stockpile
GitGuardian counted 23.8 million secrets leaked on public GitHub in 2024, 25 percent more than in 2023, and found that 70 percent of those leaked in 2022 were still valid5. That is a vendor’s count of leaks of every origin, not only those linked to assistants. Its value for you is the second number: exposure is long-lived because rotation is slow.
With an assistant in the loop, secrets leave by three routes. They go in prompts and file context that the tool sends to its vendor. They get written into generated code, such as a sample with a real key in it. And they are read out of the environment by a tool running with the developer’s permissions. The stockpile is everything already sitting in old files, shell history and environment variables, waiting for any of the three.
The controls follow the three routes:
- Keep real credentials out of the tool’s reach. Development uses fake or sandbox keys. Production secrets live in a secrets manager and never in a file the assistant can open. Most tools can be told to ignore certain files; check how yours does it, because the settings differ by product and change often.
- Scan before the code leaves the laptop. A pre-commit scan and a server-side push block catch the sample with the real key. Expect false positives and decide who triages them.
- Shorten the life of what can leak. Give each assistant and each automation its own scoped, expiring token. Set a rotation target for confirmed exposure, such as four hours as an illustrative start, and rehearse it once.
Trusted output: insecure patterns arrive fluent
The third exposure is human. Perry and colleagues ran a user study on security-related programming tasks. Participants with an AI assistant wrote significantly less secure code than those without one, and were more likely to believe their code was secure. Those who trusted the assistant less, and worked harder on how they phrased their requests, produced fewer vulnerabilities6. The study used one model of its time and a set of tasks the authors chose, so it does not size the effect for today’s tools. Its useful finding for a manager is the last one: skepticism helped. The evidence is not one-sided: in Sandoval and colleagues’ study of 58 student programmers writing low-level C with a code assistant, assisted users produced critical security bugs at a rate no more than 10 percent higher than the unassisted control7. Different language, task and participants, so the two studies bound the question and neither settles it for your stack.
Your control is a review habit, not a ban. For code that touches authentication, input handling, cryptography or data access, reviewers ask four things: does it check who is calling, does it treat input as hostile, does it use the platform’s vetted library instead of a hand-written routine, and does it log without exposing secrets? Static analysis in the pipeline, the last chapter’s subject, catches the patterns it knows; the review catches intent.
The five-control set
Put together, the controls fit on one page. Each has an owner who is a named person, and each has a check you can run without asking anyone’s opinion.
A sixth item belongs beside the table: a software bill of materials generated on every build. It does not prevent anything. It answers, within minutes, whether a named bad version is in your product, which is the question you will be asked the day a package in the news matches one you use. For covered products it also supports the Cyber Resilience Act’s requirement.
A team-sized worked example
The scenario here is made up, with invented numbers, offered as a pattern to adapt rather than a report of any real team. Ten engineers run a Node.js service and use assistants daily. The manager adds the five controls in one sprint, with two weeks as the unit.
In that sprint the assistants propose 14 dependencies across six pull requests. The proxy resolves 11 straight away because they are already approved. The other 3 go to the exception path. One name does not exist in the registry, and the engineer drops it and writes the function by hand. One package exists, but its newest version was published 6 days earlier, below the 7-day starting value, so it waits and is installed the next week. One passes every check and is added. So 11 were approved already and 3 went to the exception path (11 + 3 = 14): 1 invented, 1 too young for now, and 1 approved and added.
Across the quarter the secret scanner blocks 6 commits. Four are test fixtures that only look like keys, so the team adds them to an ignore list with a reviewer. Two are real keys, one for a staging database and one for a cloud account. Both are rotated within the 4-hour starting target, so 2 of 2 inside the threshold. The manager reads three numbers in the monthly review: bypasses of the proxy (0), exceptions answered in two business days (3 of 3), and rotation time (both under 4 hours). Lead time for changes did not move in this invented case, which was the check that the controls were not just slowing people down. Every figure here is illustrative.
What this means for engineering managers
Monday action (owner: you, the manager, until you name an allowlist owner): ask the team to run npm ls or its equivalent and report how many installed packages are not on any list,
then decide who owns the allowlist. Then copy this skeleton into your team page.
Check yourself
- An assistant’s suggested package name can be trusted if it looks like a well-known library.
- In the Spracklen study, every model hallucinated packages at the same rate.
- Turning off install scripts for unreviewed packages removes the moment at which the Nx payload ran.
- A local AI command-line tool is safe because it only does what the developer asks.
- Slow rotation is part of why leaked secrets stay dangerous.
- A cooling period for new versions protects against any malicious package.
Reflection
What comes next
Containing risk today protects the release, but a codebase can also decay slowly with no incident at all. The next chapter, Technical Debt and Code Quality Drift, sets the signals, review cadence and refactoring budget that show decay early.
Laws referenced
Not legal advice. Laws change; verify before relying on this, and consult counsel for decisions.
EU Cyber Resilience Act · EU
Regulation (EU) 2024/2847
Products with digital elements sold in the EU, including software and AI-enabled products, must meet essential cybersecurity requirements across their life: secure by design, vulnerability handling and security updates, a software bill of materials, and reporting of exploited vulnerabilities. Code written with AI assistance is covered like any other code in the product.
- 2024-12-10 — Entered into force
- 2026-09-11 — Manufacturers must report actively exploited vulnerabilities and severe incidents
- 2027-12-11 — Main obligations apply
Last verified 2026-10-08 · official text
General Data Protection Regulation · EU
Regulation (EU) 2016/679
Personal data is any information relating to an identified or identifiable person, directly or indirectly, including by an identifier such as an online ID (Art. 4(1)). Lawful basis and purpose limitation (Arts. 5-6); processing special-category data, including biometric data used to identify a person, health data and data revealing ethnicity, is prohibited unless a specific exception applies (Art. 9); data protection by design and by default (Art. 25); processors such as AI vendors may act only under a written contract with required terms and sufficient guarantees (Art. 28); transparency to data subjects (Arts. 13-14); right not to be subject to a decision based solely on automated processing with legal or similarly significant effects (Art. 22); breach notification to the supervisory authority within 72 hours (Art. 33) and to individuals without undue delay when the risk is high (Art. 34); data protection impact assessment for high-risk processing (Art. 35). Fines up to EUR 20 million or 4% of global turnover.
- 2018-05-25 — Applies
Last verified 2026-10-08 · official text
References
- The Register. AI hallucinates software packages and devs download them. The Register. 2024.
- Joseph Spracklen, Raveen Wijewickrama, A H M Nazmus Sakib, Anindya Maiti, Bimal Viswanath and Murtuza Jadliwala. We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs. USENIX Security Symposium 2025. 2025.
- Nx (Nrwl). GitHub Security Advisory GHSA-cxm3-wv7p-598c: malicious versions of Nx and plugin packages. GitHub Security Advisories, nrwl/nx. 2025.
- The Hacker News. Malicious Nx Packages in 's1ngularity' Attack Leaked 2,349 GitHub, Cloud, and AI Credentials. The Hacker News. 2025.
- GitGuardian. The State of Secrets Sprawl 2025. GitGuardian blog. 2025.
- Neil Perry, Megha Srivastava, Deepak Kumar and Dan Boneh. Do Users Write More Insecure Code with AI Assistants?. ACM CCS 2023, pages 2785-2799. 2023.
- New York University. Lost at C: A User Study on the Security Implications of Large Language Model Code Assistants. USENIX Security Symposium. 2023.
Further reading
- Joseph Spracklen, Raveen Wijewickrama, A H M Nazmus Sakib, Anindya Maiti, Bimal Viswanath and Murtuza Jadliwala. We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs. USENIX Security Symposium 2025. 2025.
- Neil Perry, Megha Srivastava, Deepak Kumar and Dan Boneh. Do Users Write More Insecure Code with AI Assistants?. ACM CCS 2023, pages 2785-2799. 2023.
- New York University. Lost at C: A User Study on the Security Implications of Large Language Model Code Assistants. USENIX Security Symposium. 2023.
- GitGuardian. The State of Secrets Sprawl 2025. GitGuardian blog. 2025.
Sources last verified 2026-10-12.