Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

connect-block-hotlinks

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

connect-block-hotlinks

Middleware for blocking cross-origin requests (hotlinks)

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

I wrote this middleware to keep people from embedding my site's images into their own sites. It compares the HTTP headers Host and Referer to make sure they are from the same 2nd-level domain. For example, if Host is img.example.com then referer can be http://example.com/ or http://blog.example.com/ but not http://another.com/.

This will not stop a determined attacker! For that you should use CORS and authentication mechanisms. But it will prevent people stealing your bandwidth by using a URL to your image in the 'src' of an tag on another site.

API

It follows a classic Connect/Express middleware pattern:

var express = require('express');
var blockHotlinks = require('connect-block-hotlinks');

var app = express();
app.use "/img/*", blockHotlinks

Depending on the request, the middleware will either:

  • do nothing, and call next() so the route can be handled by the next route handler.
  • return a 403 Forbidden "Missing 'Host' HTTP Header"
  • return a 403 Forbidden "Missing 'Referer' HTTP Header"
  • return a 200 OK hotlinking-disallowed.png

Keywords

FAQs

Package last updated on 07 Oct 2015

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc