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

cloudflare-origin-pull

v1.0.1

Published

Verify that TLS peer certificates came from CloudFlare

Downloads

34

Readme

cloudflare-origin-pull

CloudFlare has an Authenticated Origin Pulls mode where requests to your origin servers present a CloudFlare issued certificate. This module helps you verify requests to your Node server came from CloudFlare without needing to change how your own SSL certificate is served.

This module has been tested with Node.js 0.10 and above.

You may also be interested in securing access to your origin servers.

Installation

npm install --save cloudflare-origin-pull

Usage

You'll need to run an HTTPS server for this to work. In the example below that's done assuming a certificate in PKCS #12 format named my-cert.p12.

Add the requestCert option and set it to true. This causes your HTTPS server to request the peer certificate from CloudFlare.

Set rejectUnauthorized to false. This allows you to verify the peer certificate yourself.

req.client is a TLSSocket. getPeerCertificate() returns what we hope is CloudFlare's certificate.

The cloudflare-origin-pull module exports a verify() method. Call it with the peer certificate, if any. It verifies whether the certificate was issued by CloudFlare and if it has not yet expired, returning a boolean. verify() does not throw errors and can be called without a certificate (it'll return false).

Simply destroy the client connection if the certificate was not from CloudFlare or no certificate was presented at all.

const https = require('https')
const verify = require('cloudflare-origin-pull').verify

https.createServer({
  pfx: 'my-cert.p12',
  requestCert: true,
  rejectUnauthorized: false
}, (req, res) => {
  if (!verify(req.client.getPeerCertificate())) {
    req.client.destroy()
    return
  }

  res.writeHead(200)
  res.end('You’re cool.')
})