Learn / Security / Lesson 06

Third-party scripts and dependencies

Every script you load from someone else runs with your page's full power. Real breaches that came in through a chat widget, a CDN and an npm package.

Last updated: 2026-09-19

What it is

A <script src="https://someone-else.com/x.js"> tag hands that other company the keys to your page. Their code can read every form field, every price and every piece of data on screen, and send it anywhere. The same goes for every npm package in your server: it runs with your database password in memory.

This is the supply chain: code you did not write, running as if you did.

Why it is a rule

How to do it

Serve it yourself

If a file can live on your own server, put it there. A copy you host cannot be changed under you by someone else, and it keeps working when their CDN is slow or blocked.

Pin it with Subresource Integrity

When a script must come from a CDN, pin the exact bytes you reviewed:

html
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/lib.min.js"
        integrity="sha384-…"
        crossorigin="anonymous"></script>

If the file changes by one byte, the browser refuses to run it.

Keep secrets away from third-party code

Pages that show private data (dashboards, books, payments) load the fewest outside scripts, ideally none. An analytics tag has no business on a page that shows a client's ledger.

Lock and review dependencies

Keep a list

Every outside script, font, pixel and API: what it receives, where it sends it, and why you need it. The privacy policy names each one.

How we do it here

The public site self-hosts its fonts, icons and scripts. Part of the reason is security, and part is that third-party hosts often fail behind the TLS-intercepting proxies common on Philippine networks. Pages that show client data do not load analytics or marketing tags.

Benefits

Disadvantages

Checklist

Sources

Read this lesson as Markdown