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

browser-csrf

v1.1.0

Published

Inject CSRF tokens into your browser's network requests

Downloads

1

Readme

browser-csrf :lock:

inject csrf tokens into your browser's network calls.

Codeship Status for cdaringe/browser-csrf Sauce Test Status

what

injects a token on each:

  • xhr request
  • fetch request
  • form submission

usage

// example
var BrowserCSRF = require('browser-csrf')
var bcsrf = new BrowserCSRF({ token: '<your-csrf-token>' })
bcsrf.inject()

this is a fairly simple example. see the API docs for more.

api

See the official API Docs.

why

CSRF attacks are real. Using an authorization token on each request (such as a CSRF token) helps prevent unauthorization command execution. Using cookies to store auth tokens generally works, but leaves your app vulnerable to malicious social engineering. Malicious actors can lead your users to make network calls against your server using an entirely different website, via HTML forms or cross-origin javascript XHRs, exploiting the fact that your cookies will be passed along, even outside the context your website/domain!

how

how we do this is controversial! we override the XMLHttpRequest.prototype.send method, add a header, & reproxy through to the original method. if you are not comfortable with this, this module isn't for you!

example exploit

See the exploit/ directory for an easy to run, easy to understand example of CSRF.

here's how you can use the demo:

  • launch both servers, node exploit/<malicious/vulnerable>/src/index.js
  • open a browser to localhost:7777
    • log into the fake bank using the displayed credentials
    • simulate some fund transfers (the ui makes this clear how to do, hopefully :))
    • observe the exploit link at the bottom of the page. click it
      • this link opens a website from the malicious server, and makes your browser execute a command against the vulnerable server on your behalf, unbeknownst to you! this is the very essence of a CSRF!

hopefully you can see that another site's ability to issue a command on a completely different site using an existing authenticated session is a big deal. so, how can we fix it? OWASP has some great documentation on how the attack vectors work. they also provide some basic mechanisms on how to thwart the attack vector from the browser. however, the browser solutions they provide are not very robust for modern native webapps. this browser-csrf fills that gap.

what we will do now is tell our vulnerable server to sniff for CSRF tokens.

  • kill the current vulnerable server
  • reboot the vulnerable server as such, CSRF_PROTECTION=true node exploit/vulnerable/src/index.js
    • re-navigate to localhost:7777
    • on login, the server provides a CSRF token
    • our browser code, post-login, sets up browser-csrf to make sure each network request gets the token injected into request headers
    • our server will now sniff for CSRF tokens on each request that requires authentication
  • repeat the above banking processes
    • observe fund transfers work fine!
    • observe the CSRF attack thwarted from the malicious site!