Socket
Socket
Sign inDemoInstall

check-referrer

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    check-referrer

middleware for routing requests based on referrer


Version published
Weekly downloads
9
increased by800%
Maintainers
1
Install size
7.11 kB
Created
Weekly downloads
 

Readme

Source

check-referrer

middleware for routing requests based on referrer

npm install check-referrer

###checkReferrer

Params:

  • rules String

    list of routing rules

    • - means exclude from redirect
    • + means only exclude from redirect
  • redirect String

    route for redirect

req.fromAllowedReferrer will be set to true for whitelisted referrers

examples

By default, all requests are redirected.

To exclude urls from redirection use '-'

// Whitelist requests from example.com
var checkReferrer = require('check-referrer');
app.use(checkReferrer('-example.com'));
// req.fromAllowedReferrer will be set to true in all middleware that runs after a request from example.com
// Only allow and whitelist requests from example.com
var checkReferrer = require('check-referrer');
app.use(checkReferrer('-example.com', '/redirect-here'));

To redirect only specific urls while allowing all others, use '+'

// Only redirect requests from example.com
var checkReferrer = require('check-referrer');
app.use(checkReferrer('+example.com', '/redirect-here'));

Seperate rules with a comma

// Only allow requests from certain domains
var checkReferrer = require('check-referrer');
app.use(checkReferrer('-example.com,-mysite.com,-othersite.com', '/redirect-here'));

The rule doesn't have to be a url

// Only allow visitors with a secret referrer key
var checkReferrer = require('check-referrer');
app.use(checkReferrer('-my_secret_key', '/redirect-here'));

caveats

This is "security" by obscurity, similar to passwords. If somone knows your password, then its useless. Likewise, if the visitor knows which referrers are allowed, they can easily spoof their referrer.

Keywords

FAQs

Last updated on 26 May 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc