1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: use ip-address for remote-strategy (#8380)

Removed direct dependency on ip in favor of maintained `ip-address`.

Copied from unleash-client-node.
This commit is contained in:
Christopher Kolstad 2024-10-07 13:51:03 +02:00 committed by GitHub
parent 864984e212
commit 942555b993
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 8 deletions

View File

@ -134,7 +134,7 @@
"hash-sum": "^2.0.0",
"helmet": "^6.0.0",
"http-errors": "^2.0.0",
"ip": "^2.0.1",
"ip-address": "^10.0.0",
"joi": "^17.13.3",
"js-sha256": "^0.11.0",
"js-yaml": "^4.1.0",

View File

@ -1,6 +1,6 @@
import { Strategy } from './strategy';
import type { Context } from '../context';
import ip from 'ip';
import { Address4 } from 'ip-address';
export default class RemoteAddressStrategy extends Strategy {
constructor() {
@ -16,16 +16,17 @@ export default class RemoteAddressStrategy extends Strategy {
if (range === context.remoteAddress) {
return true;
}
if (!ip.isV6Format(range)) {
if (Address4.isValid(range)) {
try {
return ip
.cidrSubnet(range)
.contains(context.remoteAddress);
const subnetRange = new Address4(range);
const remoteAddress = new Address4(
context.remoteAddress || '',
);
return remoteAddress.isInSubnet(subnetRange);
} catch (err) {
return false;
}
}
return false;
},
);
}

View File

@ -5129,6 +5129,13 @@ __metadata:
languageName: node
linkType: hard
"ip-address@npm:^10.0.0":
version: 10.0.0
resolution: "ip-address@npm:10.0.0"
checksum: 10c0/de28efeac726bce4a088ad2b31a3eefaf8d0f586ece6808366aef68029c0ad1387c1db98de23ddb1a888caf914de80424c1baf548e580dae65e0a9b24073f542
languageName: node
linkType: hard
"ip-address@npm:^9.0.5":
version: 9.0.5
resolution: "ip-address@npm:9.0.5"
@ -9461,7 +9468,7 @@ __metadata:
helmet: "npm:^6.0.0"
http-errors: "npm:^2.0.0"
husky: "npm:^9.0.11"
ip: "npm:^2.0.1"
ip-address: "npm:^10.0.0"
jest: "npm:29.7.0"
jest-junit: "npm:^16.0.0"
joi: "npm:^17.13.3"