mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +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:
		
							parent
							
								
									864984e212
								
							
						
					
					
						commit
						942555b993
					
				@ -134,7 +134,7 @@
 | 
				
			|||||||
    "hash-sum": "^2.0.0",
 | 
					    "hash-sum": "^2.0.0",
 | 
				
			||||||
    "helmet": "^6.0.0",
 | 
					    "helmet": "^6.0.0",
 | 
				
			||||||
    "http-errors": "^2.0.0",
 | 
					    "http-errors": "^2.0.0",
 | 
				
			||||||
    "ip": "^2.0.1",
 | 
					    "ip-address": "^10.0.0",
 | 
				
			||||||
    "joi": "^17.13.3",
 | 
					    "joi": "^17.13.3",
 | 
				
			||||||
    "js-sha256": "^0.11.0",
 | 
					    "js-sha256": "^0.11.0",
 | 
				
			||||||
    "js-yaml": "^4.1.0",
 | 
					    "js-yaml": "^4.1.0",
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,6 @@
 | 
				
			|||||||
import { Strategy } from './strategy';
 | 
					import { Strategy } from './strategy';
 | 
				
			||||||
import type { Context } from '../context';
 | 
					import type { Context } from '../context';
 | 
				
			||||||
import ip from 'ip';
 | 
					import { Address4 } from 'ip-address';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class RemoteAddressStrategy extends Strategy {
 | 
					export default class RemoteAddressStrategy extends Strategy {
 | 
				
			||||||
    constructor() {
 | 
					    constructor() {
 | 
				
			||||||
@ -16,16 +16,17 @@ export default class RemoteAddressStrategy extends Strategy {
 | 
				
			|||||||
                if (range === context.remoteAddress) {
 | 
					                if (range === context.remoteAddress) {
 | 
				
			||||||
                    return true;
 | 
					                    return true;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (!ip.isV6Format(range)) {
 | 
					                if (Address4.isValid(range)) {
 | 
				
			||||||
                    try {
 | 
					                    try {
 | 
				
			||||||
                        return ip
 | 
					                        const subnetRange = new Address4(range);
 | 
				
			||||||
                            .cidrSubnet(range)
 | 
					                        const remoteAddress = new Address4(
 | 
				
			||||||
                            .contains(context.remoteAddress);
 | 
					                            context.remoteAddress || '',
 | 
				
			||||||
 | 
					                        );
 | 
				
			||||||
 | 
					                        return remoteAddress.isInSubnet(subnetRange);
 | 
				
			||||||
                    } catch (err) {
 | 
					                    } catch (err) {
 | 
				
			||||||
                        return false;
 | 
					                        return false;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -5129,6 +5129,13 @@ __metadata:
 | 
				
			|||||||
  languageName: node
 | 
					  languageName: node
 | 
				
			||||||
  linkType: hard
 | 
					  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":
 | 
					"ip-address@npm:^9.0.5":
 | 
				
			||||||
  version: 9.0.5
 | 
					  version: 9.0.5
 | 
				
			||||||
  resolution: "ip-address@npm:9.0.5"
 | 
					  resolution: "ip-address@npm:9.0.5"
 | 
				
			||||||
@ -9461,7 +9468,7 @@ __metadata:
 | 
				
			|||||||
    helmet: "npm:^6.0.0"
 | 
					    helmet: "npm:^6.0.0"
 | 
				
			||||||
    http-errors: "npm:^2.0.0"
 | 
					    http-errors: "npm:^2.0.0"
 | 
				
			||||||
    husky: "npm:^9.0.11"
 | 
					    husky: "npm:^9.0.11"
 | 
				
			||||||
    ip: "npm:^2.0.1"
 | 
					    ip-address: "npm:^10.0.0"
 | 
				
			||||||
    jest: "npm:29.7.0"
 | 
					    jest: "npm:29.7.0"
 | 
				
			||||||
    jest-junit: "npm:^16.0.0"
 | 
					    jest-junit: "npm:^16.0.0"
 | 
				
			||||||
    joi: "npm:^17.13.3"
 | 
					    joi: "npm:^17.13.3"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user