diff --git a/package.json b/package.json index b4478faa9b..eae82aa62d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/features/playground/feature-evaluator/strategy/remote-address-strategy.ts b/src/lib/features/playground/feature-evaluator/strategy/remote-address-strategy.ts index 237a7208fd..9580895409 100644 --- a/src/lib/features/playground/feature-evaluator/strategy/remote-address-strategy.ts +++ b/src/lib/features/playground/feature-evaluator/strategy/remote-address-strategy.ts @@ -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; }, ); } diff --git a/yarn.lock b/yarn.lock index 101a6b5b3f..b63ead5021 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"