npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@weizman/shield

v0.0.1

Published

Shield your DOM against clobbering attacks effortlessly

Downloads

11

Readme

Shield JS 🛡

Shield (npm) is a tiny JavaScript shim/library that applies protection against DOM Clobbering attacks at runtime with close to zero integration friction.

See for yourself - visit live demo/playground

Installation

Include Shield via a script tag:

<script src="https://cdn.jsdelivr.net/npm/@weizman/shield/shield.min.js"></script>

That's it.

It's best to include it as close as possible to the beginning of the <head> (the earliest it runs, the better it protects).

Usage

Shield supports optional configuration:

<script src="https://cdn.jsdelivr.net/npm/@weizman/shield/shield.min.js"
        allowlist="id1,id2"
        reportOnly="false"
        reportTo="https://report-server/report/"
></script>
  • allowlist - a list of ids you allow to be clobbered into the DOM (shield will overlook them when applying its protection).
  • reportOnly - whether to report forbidden access attempt or to throw an error. If enabled, reportTo must also be provided.
  • reportTo - a valid https: URL to report forbidden access attempt to in case reportOnly is enabled (CSP format):
{
    "csp-report": {
        "blocked-property": "id3",
        "disposition": "report",
        "document-uri": "https://my-app.com/some-route/",
        "effective-directive": "dom-clobbering",
        "original-policy": "no-access",
        "referrer": "https://my-app.com/some-route/",
        "violated-directive": "dom-clobbering"
    }
}

Result

Shield will collect the values of all id/name properties that were introduced to DOM at runtime and will redefine them on the window to throw an error when JavaScript code attempts to access them.

That's because while we use id/name attributes for our DOM nodes, we don't expect JavaScript code to access them, so when this happens it can only be done by a malicious entity - and that's what Shield blocks:

Unless the id/name was explicitly provided via the allowlist argument, which in that case Shield will allow JavaScript to access it:

Making Shield a very simple and elegant solution that requires you to do nothing but include the script in your app - shield will do the rest!

About