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

@tinyhttp/proxy-addr

Package Overview
Dependencies
Maintainers
0
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 2.1.3 to 2.1.4

vite.config.ts

4

dist/index.d.ts

@@ -1,4 +0,4 @@

/// <reference types="node" />
import type { IncomingMessage } from 'node:http';
import { IncomingMessage } from 'node:http';
import { IPv6, IPv4 } from 'ipaddr.js';
type Req = Pick<IncomingMessage, 'headers' | 'socket'>;

@@ -5,0 +5,0 @@ type Trust = ((addr: string, i: number) => boolean) | number[] | string[] | string;

@@ -14,9 +14,6 @@ import { forwarded } from "@tinyhttp/forwarded";

const addrs = forwarded(req);
if (!trust)
return addrs;
if (typeof trust !== "function")
trust = compile(trust);
if (!trust) return addrs;
if (typeof trust !== "function") trust = compile(trust);
for (let i = 0; i < addrs.length - 1; i++) {
if (trust(addrs[i], i))
continue;
if (trust(addrs[i], i)) continue;
addrs.length = i + 1;

@@ -28,12 +25,8 @@ }

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;
val = IP_RANGES[val];

@@ -47,4 +40,3 @@ trust.splice.apply(trust, [i, 1].concat(val));

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;

@@ -59,22 +51,15 @@ }

const str = pos !== -1 ? note.substring(0, pos) : note;
if (!isip(str))
throw new TypeError("invalid IP address: " + 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())
ip = ip.toIPv4Address();
if (ip.isIPv4MappedAddress()) ip = ip.toIPv4Address();
}
const max = ip.kind() === "ipv6" ? 128 : 32;
let range = pos !== -1 ? note.substring(pos + 1, note.length) : null;
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
range = null;
if (typeof range === "number" && (range <= 0 || range > max))
throw new TypeError("invalid range on address: " + note);
if (range === null) range = max;
else if (DIGIT_REGEXP.test(range)) range = Number.parseInt(range, 10);
else if (ip.kind() === "ipv4" && isip(range)) range = parseNetmask(range);
else range = null;
if (typeof range === "number" && (range <= 0 || range > max)) throw new TypeError(`invalid range on address: ${note}`);
return [ip, range];

@@ -92,4 +77,3 @@ }

return function trust(addr) {
if (!isip(addr))
return false;
if (!isip(addr)) return false;
const ip = parseip(addr);

@@ -105,10 +89,7 @@ let ipconv;

if (kind !== subnetkind) {
if (subnetkind === "ipv4" && !ip.isIPv4MappedAddress())
continue;
if (!ipconv)
ipconv = subnetkind === "ipv4" ? ip.toIPv4Address() : ip.toIPv4MappedAddress();
if (subnetkind === "ipv4" && !ip.isIPv4MappedAddress()) continue;
if (!ipconv) ipconv = subnetkind === "ipv4" ? ip.toIPv4Address() : ip.toIPv4MappedAddress();
trusted = ipconv;
}
if (trusted.match(subnetip, subnetrange))
return true;
if (trusted.match(subnetip, subnetrange)) return true;
}

@@ -124,9 +105,7 @@ return false;

return function trust(addr) {
if (!isip(addr))
return false;
if (!isip(addr)) return false;
let ip = parseip(addr);
const kind = ip.kind();
if (kind !== subnetkind) {
if (subnetisipv4 && !ip.isIPv4MappedAddress())
return false;
if (subnetisipv4 && !ip.isIPv4MappedAddress()) return false;
ip = subnetisipv4 ? ip.toIPv4Address() : ip.toIPv4MappedAddress();

@@ -133,0 +112,0 @@ }

{
"name": "@tinyhttp/proxy-addr",
"version": "2.1.3",
"version": "2.1.4",
"type": "module",

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

"dependencies": {
"ipaddr.js": "^2.1.0",
"@tinyhttp/forwarded": "2.1.2"
"ipaddr.js": "^2.2.0",
"@tinyhttp/forwarded": "2.1.1"
},
"files": [
"dist"
],
"scripts": {

@@ -39,0 +36,0 @@ "dev": "vite",

Sorry, the diff of this file is not supported yet

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