<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anwar Nairi</title>
    <description>The latest articles on DEV Community by Anwar Nairi (@anwar_nairi_f2f3d79992168).</description>
    <link>https://dev.to/anwar_nairi_f2f3d79992168</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3769701%2F0b1fd755-8311-4de6-9454-f98cba84dd66.jpg</url>
      <title>DEV Community: Anwar Nairi</title>
      <link>https://dev.to/anwar_nairi_f2f3d79992168</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anwar_nairi_f2f3d79992168"/>
    <language>en</language>
    <item>
      <title>Lock your dependency to prevent supply-chain attacks</title>
      <dc:creator>Anwar Nairi</dc:creator>
      <pubDate>Tue, 12 May 2026 17:30:27 +0000</pubDate>
      <link>https://dev.to/anwar_nairi_f2f3d79992168/lock-your-dependency-to-prevent-supply-chain-attacks-24a5</link>
      <guid>https://dev.to/anwar_nairi_f2f3d79992168/lock-your-dependency-to-prevent-supply-chain-attacks-24a5</guid>
      <description>&lt;p&gt;If you followed recent news, a new &lt;a href="https://tanstack.com/blog/npm-supply-chain-compromise-postmortem" rel="noopener noreferrer"&gt;supply-chain attack&lt;/a&gt; affected recent versions of several TanStack packages.&lt;/p&gt;

&lt;p&gt;This article proposes a simple approach to reduce the likelihood and impact of this kind of security breach in your applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;What is a supply-chain attack?&lt;/li&gt;
&lt;li&gt;What happened?&lt;/li&gt;
&lt;li&gt;Why did it affect other projects?&lt;/li&gt;
&lt;li&gt;How version locking reduces risks&lt;/li&gt;
&lt;li&gt;Limitations of this solution&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What is a supply-chain attack?
&lt;/h2&gt;

&lt;p&gt;A software package depends on multiple elements throughout its lifecycle:&lt;/p&gt;

&lt;p&gt;Developer -&amp;gt; Computer -&amp;gt; GitHub Repository -&amp;gt; Package Registry (NPM)&lt;/p&gt;

&lt;p&gt;A supply-chain attack happens when one of these elements is compromised, allowing malicious code to propagate through the rest of the chain.&lt;/p&gt;

&lt;p&gt;In practice, this often means an attacker manages to inject malicious code into a package that many other projects depend on.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happened?
&lt;/h2&gt;

&lt;p&gt;An attacker submitted a malicious pull request targeting one of the TanStack packages.&lt;/p&gt;

&lt;p&gt;The pull request contained hidden malicious JavaScript code. During the CI process, a GitHub Action workflow executed and the attack poisoned the GitHub Actions cache.&lt;/p&gt;

&lt;p&gt;The malicious code was then able to capture sensitive credentials, including GitHub tokens.&lt;/p&gt;

&lt;p&gt;Using those credentials, the attacker gained elevated permissions and published compromised package versions to NPM.&lt;/p&gt;

&lt;p&gt;As a result, developers installing the affected versions unknowingly downloaded malicious code into their projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why did it affect other projects
&lt;/h2&gt;

&lt;p&gt;By default, Node.js projects usually allow dependency updates within the same major version.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;solid-js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This produces the following entry in &lt;code&gt;package.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"solid-js"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"^1.9.5"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;^&lt;/code&gt; character means:&lt;/p&gt;

&lt;p&gt;Allow future minor and patch updates automatically.&lt;/p&gt;

&lt;p&gt;So even if your project originally used &lt;code&gt;1.9.5&lt;/code&gt;, reinstalling dependencies later may install a newer version such as &lt;code&gt;1.11.2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This can happen in many situations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A new developer joins the team and installs dependencies&lt;/li&gt;
&lt;li&gt;A CI/CD pipeline runs &lt;code&gt;npm install&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;A GitHub Action executes automated tests&lt;/li&gt;
&lt;li&gt;You reinstall dependencies after deleting &lt;code&gt;node_modules&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You run &lt;code&gt;npm update&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If a malicious version is published during that time window, your project may automatically fetch it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How version locking reduces risks
&lt;/h2&gt;

&lt;p&gt;The goal is simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If version &lt;code&gt;X.Y.Z&lt;/code&gt; worked yesterday, install that exact same version tomorrow.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;NPM provides a &lt;code&gt;--save-exact&lt;/code&gt; flag for this purpose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-exact&lt;/span&gt; solid-js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"solid-js"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.9.5"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that the &lt;code&gt;^&lt;/code&gt; is gone.&lt;/p&gt;

&lt;p&gt;Now every npm install will use the exact same version unless you explicitly change it yourself.&lt;/p&gt;

&lt;p&gt;You can also lock a specific version manually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-exact&lt;/span&gt; solid-js@1.8.0 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach exists in many ecosystems.&lt;/p&gt;

&lt;p&gt;PHP&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require laravel/reverb:1.10.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ruby&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gem &lt;span class="nb"&gt;install &lt;/span&gt;sidekiq &lt;span class="nt"&gt;-v&lt;/span&gt; 8.1.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;poetry add requests@2.34.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Limitations to this solution
&lt;/h2&gt;

&lt;p&gt;As always in software engineering, there is no free lunch.&lt;/p&gt;

&lt;p&gt;This approach comes with several trade-offs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You must review and update dependencies manually&lt;/li&gt;
&lt;li&gt;You should run &lt;code&gt;npm outdated&lt;/code&gt; regularly to stay up to date on security fixes&lt;/li&gt;
&lt;li&gt;Locking direct dependencies does not fully protect you from compromised transitive dependencies&lt;/li&gt;
&lt;li&gt;Security vulnerabilities may remain unnoticed longer if updates are delayed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, version locking reduces the attack surface, but it does not eliminate supply-chain risks entirely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Supply-chain attacks require active monitoring and good security practices.&lt;/p&gt;

&lt;p&gt;Exact version locking is not a silver bullet, but it helps reduce unpredictability and limits the risk of accidentally installing newly compromised package versions.&lt;/p&gt;

&lt;p&gt;An additional benefit is build reproducibility:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;team members use the same dependency versions&lt;/li&gt;
&lt;li&gt;CI environments become more predictable&lt;/li&gt;
&lt;li&gt;debugging becomes easier&lt;/li&gt;
&lt;li&gt;unexpected dependency regressions are reduced&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, this approach also increases maintenance overhead because dependency upgrades must be reviewed more carefully.&lt;/p&gt;

&lt;p&gt;For some teams, this trade-off is worth it. For others, it may feel too restrictive.&lt;/p&gt;

&lt;p&gt;The important part is understanding the risks and making an intentional decision rather than relying on default package manager behavior.&lt;/p&gt;

&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@kommumikation?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Mika Baumeister&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/a-tug-boat-pulling-a-large-container-ship-3XjMwxUHx0Q?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>security</category>
    </item>
  </channel>
</rss>
