New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

redirect-ssl

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redirect-ssl - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

yarn-error.log

31

index.js

@@ -0,36 +1,19 @@

const isHTTPS = require('is-https')
// Default options
const defaults = {
xForwardedProto: true,
redirectPort: 443,
redirectHost: undefined,
statusCode: 307
xForwardedProto: true,
redirectPort: 443,
redirectHost: undefined,
statusCode: 307
}
function isEmpty(v) {
return v === undefined || v === null
}
// Creates new middleware using provided options
function create(options) {
const { xForwardedProto, redirectPort, redirectHost, statusCode } = Object.assign({}, defaults, options)
const _port = redirectPort === 443 ? '' : (': ' + redirectPort)
return function redirectSSL(req, res, next) {
// Test using req.connection.encrypted
const _encrypted = isEmpty(req.connection.encrypted) ? null : req.connection.encrypted === true
// Test using req.protocol
const _httpsProtocol = isEmpty(req.protocol) ? null : req.protocol === 'https'
// Test using x-forwarded-proto header
const _httpsXforwarded = (!xForwardedProto || isEmpty(req.headers['x-forwarded-proto'])) ? null
: req.headers['x-forwarded-proto'].indexOf('https') !== -1
const _noDetectionMethod = _encrypted === null && _httpsProtocol === null && _httpsXforwarded === null
if (_encrypted || _httpsProtocol || _httpsXforwarded || _noDetectionMethod) {
return next()
if (isHTTPS(req, xForwardedProto) !== false) {
return next()
}

@@ -37,0 +20,0 @@

{
"name": "redirect-ssl",
"version": "0.1.0",
"version": "1.0.0",
"description": "Connect middleware to enforce https",

@@ -12,3 +12,6 @@ "main": "index.js",

"pem": "^1.9.7"
},
"dependencies": {
"is-https": "^1.0.0"
}
}
# redirect-ssl
> Connect/Express middleware to enforce https.
> Connect/Express middleware to enforce https using [is-https](https://www.npmjs.com/package/is-https).

@@ -7,10 +7,2 @@ [![npm](https://img.shields.io/npm/dt/redirect-ssl.svg?style=flat-square)](https://npmjs.com/package/redirect-ssl)

## Behaviour
This middleware tries to use 3 standard checks for HTTPS detection:
- Test if `req.connection.encrypted` is `true`
- Test if `req.protocol` is `https`
- Test if `x-forwarded-proto` header contains `https`
If all tests are unavailable, middleware just continues to avoid redirect loops.
If any test fails, middleware ends reponse with a [307](#status-code) redirect to `https://[host][:port?][url]`.
## Usage

@@ -17,0 +9,0 @@ Install package

Sorry, the diff of this file is not supported yet

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