How everyone could have prevented the polyfill dot io supply chain attacks ?

how-everyone-could-have-prevented-the-polyfill-dot-io-supply-chain-attacks-?

Understanding Supply Chain Attacks

Supply chain attacks involve compromising a third-party service or library to inject malicious code into websites that rely on it. A recent example is the Polyfill.io incident, where thousands of websites were potentially compromised.

How Could This Be Prevented?

One effective way to mitigate such risks is by using the Subresource Integrity (SRI) attribute in your HTML scripts and link tags. SRI allows browsers to verify that the fetched resources (like scripts or stylesheets) are delivered without unexpected manipulation.

Demonstration

#script.js
console.log("Hello World - Secured!");
#index.html



  
  
  
  SUBRESOURCE INTEGRITY EXAMPLE


  Hello World


#app.js - to serve above files
const express = require('express');
const app = express();

app.use(express.static("./"));

app.listen(80, () => {
  console.log('Server is running on http://localhost');
});

Generating the Integrity Hash

openssl dgst -sha384 -binary script.js | openssl base64 -A

Now if we perform all the above steps correctly then the following working output should appear:

WORKING OUTPUT IF ABOVE STEPS PERFORM CORRECTLY

Now Let’s try to modify script.js

#script.js - modified
console.log("Hello World - Modified!");

Now try to open http://localhost/index.html, you should see following error:

None of the sha384 hashes in the integrity attribute match the content of the resource.

SO THE MODIFIEFD SCRIPT WON’T RUN AT ALL!!

SCRIPT WON'T RUN AFTER MODIFICATION

Resources:

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
using-purecomponent-and-react.memo-to-improve-performance-in-react

Using PureComponent and React.memo to Improve Performance in React

Next Post
unlock-the-secret-to-perfect-ui-design!

Unlock the Secret to Perfect UI Design!

Related Posts