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

@tinyhttp/proxy-addr

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinyhttp/proxy-addr - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

6

CHANGELOG.md
# @tinyhttp/proxy-addr
## 0.5.3
### Patch Changes
- remove more newlines
## 0.5.2

@@ -4,0 +10,0 @@

51

dist/index.js

@@ -25,6 +25,4 @@ import { forwarded } from '@tinyhttp/forwarded';

const addrs = forwarded(req);
if (!trust) {
// Return all addresses
if (!trust)
return addrs;
}
if (typeof trust !== 'function')

@@ -45,20 +43,13 @@ trust = compile(trust);

function compile(val) {
if (!val) {
throw new TypeError('argument is required');
}
let trust;
if (typeof val === 'string') {
if (typeof val === 'string')
trust = [val];
}
else if (Array.isArray(val)) {
else if (Array.isArray(val))
trust = val.slice();
}
else {
else
throw new TypeError('unsupported trust argument');
}
for (let i = 0; i < trust.length; i++) {
val = trust[i];
if (!Object.prototype.hasOwnProperty.call(IP_RANGES, val)) {
if (!Object.prototype.hasOwnProperty.call(IP_RANGES, val))
continue;
}
// Splice in pre-defined range

@@ -77,5 +68,4 @@ val = IP_RANGES[val];

const rangeSubnets = new Array(arr.length);
for (let i = 0; i < arr.length; i++) {
for (let i = 0; i < arr.length; i++)
rangeSubnets[i] = parseIPNotation(arr[i]);
}
return rangeSubnets;

@@ -102,12 +92,9 @@ }

const str = pos !== -1 ? note.substring(0, pos) : note;
if (!isip(str)) {
if (!isip(str))
throw new TypeError('invalid IP address: ' + str);
}
let ip = parseip(str);
if (pos === -1 && ip.kind() === 'ipv6') {
ip = ip;
if (ip.isIPv4MappedAddress()) {
// Store as IPv4
if (ip.isIPv4MappedAddress())
ip = ip.toIPv4Address();
}
}

@@ -118,5 +105,4 @@ const max = ip.kind() === 'ipv6' ? 128 : 32;

range = max;
else if (DIGIT_REGEXP.test(range)) {
else if (DIGIT_REGEXP.test(range))
range = parseInt(range, 10);
}
else if (ip.kind() === 'ipv4' && isip(range))

@@ -126,5 +112,4 @@ range = parseNetmask(range);

range = null;
if (range <= 0 || range > max) {
if (range <= 0 || range > max)
throw new TypeError('invalid range on address: ' + note);
}
return [ip, range];

@@ -151,4 +136,3 @@ }

const addrs = alladdrs(req, trust);
const addr = addrs[addrs.length - 1];
return addr;
return addrs[addrs.length - 1];
}

@@ -177,10 +161,6 @@ /**

if (kind !== subnetkind) {
if (subnetkind === 'ipv4' && !ip.isIPv4MappedAddress()) {
// Incompatible IP addresses
if (subnetkind === 'ipv4' && !ip.isIPv4MappedAddress())
continue;
}
if (!ipconv) {
// Convert IP to match subnet IP kind
if (!ipconv)
ipconv = subnetkind === 'ipv4' ? ip.toIPv4Address() : ip.toIPv4MappedAddress();
}
trusted = ipconv;

@@ -210,7 +190,4 @@ }

if (kind !== subnetkind) {
if (subnetisipv4 && !ip.isIPv4MappedAddress()) {
// Incompatible IP addresses
if (subnetisipv4 && !ip.isIPv4MappedAddress())
return false;
}
// Convert IP to match subnet IP kind
ip = subnetisipv4 ? ip.toIPv4Address() : ip.toIPv4MappedAddress();

@@ -217,0 +194,0 @@ }

{
"name": "@tinyhttp/proxy-addr",
"version": "0.5.2",
"version": "0.5.3",
"type": "module",

@@ -5,0 +5,0 @@ "description": "proxy-addr rewrite with TypeScript and ESM support",

@@ -28,6 +28,4 @@ import { forwarded } from '@tinyhttp/forwarded'

if (!trust) {
// Return all addresses
return addrs
}
if (!trust) return addrs
if (typeof trust !== 'function') trust = compile(trust)

@@ -47,18 +45,11 @@

function compile(val: string | string[] | number[]) {
if (!val) {
throw new TypeError('argument is required')
}
let trust
if (typeof val === 'string') {
trust = [val]
} else if (Array.isArray(val)) {
trust = val.slice()
} else {
throw new TypeError('unsupported trust argument')
}
if (typeof val === 'string') trust = [val]
else if (Array.isArray(val)) trust = val.slice()
else throw new TypeError('unsupported trust argument')
for (let i = 0; i < trust.length; i++) {
val = trust[i]
if (!Object.prototype.hasOwnProperty.call(IP_RANGES, val)) {
continue
}
if (!Object.prototype.hasOwnProperty.call(IP_RANGES, val)) continue
// Splice in pre-defined range

@@ -77,5 +68,4 @@ val = IP_RANGES[val as string]

const rangeSubnets = new Array(arr.length)
for (let i = 0; i < arr.length; i++) {
rangeSubnets[i] = parseIPNotation(arr[i])
}
for (let i = 0; i < arr.length; i++) rangeSubnets[i] = parseIPNotation(arr[i])
return rangeSubnets

@@ -103,5 +93,3 @@ }

if (!isip(str)) {
throw new TypeError('invalid IP address: ' + str)
}
if (!isip(str)) throw new TypeError('invalid IP address: ' + str)

@@ -113,6 +101,3 @@ let ip = parseip(str)

if (ip.isIPv4MappedAddress()) {
// Store as IPv4
ip = ip.toIPv4Address()
}
if (ip.isIPv4MappedAddress()) ip = ip.toIPv4Address()
}

@@ -125,10 +110,7 @@

if (range === null) range = max
else if (DIGIT_REGEXP.test(range)) {
range = parseInt(range, 10)
} else if (ip.kind() === 'ipv4' && isip(range)) range = parseNetmask(range)
else if (DIGIT_REGEXP.test(range)) range = parseInt(range, 10)
else if (ip.kind() === 'ipv4' && isip(range)) range = parseNetmask(range)
else range = null
if (range <= 0 || range > max) {
throw new TypeError('invalid range on address: ' + note)
}
if (range <= 0 || range > max) throw new TypeError('invalid range on address: ' + note)

@@ -156,4 +138,4 @@ return [ip, range]

const addrs = alladdrs(req, trust)
const addr = addrs[addrs.length - 1]
return addr
return addrs[addrs.length - 1]
}

@@ -181,10 +163,6 @@ /**

if (kind !== subnetkind) {
if (subnetkind === 'ipv4' && !(ip as IPv6).isIPv4MappedAddress()) {
// Incompatible IP addresses
continue
}
if (!ipconv) {
// Convert IP to match subnet IP kind
ipconv = subnetkind === 'ipv4' ? (ip as IPv6).toIPv4Address() : (ip as IPv4).toIPv4MappedAddress()
}
if (subnetkind === 'ipv4' && !(ip as IPv6).isIPv4MappedAddress()) continue
if (!ipconv) ipconv = subnetkind === 'ipv4' ? (ip as IPv6).toIPv4Address() : (ip as IPv4).toIPv4MappedAddress()
trusted = ipconv

@@ -212,7 +190,4 @@ }

if (kind !== subnetkind) {
if (subnetisipv4 && !(ip as IPv6).isIPv4MappedAddress()) {
// Incompatible IP addresses
return false
}
// Convert IP to match subnet IP kind
if (subnetisipv4 && !(ip as IPv6).isIPv4MappedAddress()) return false
ip = subnetisipv4 ? (ip as IPv6).toIPv4Address() : (ip as IPv4).toIPv4MappedAddress()

@@ -219,0 +194,0 @@ }

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