GithubHelp home page GithubHelp logo

ip-cidr's People

Contributors

akmjenkins avatar evandarwin avatar ortexx avatar saxclar1025 avatar silverwind avatar tangent-q avatar tanver-hasan avatar terrierscript avatar zyoshoka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ip-cidr's Issues

.prototype.toArray miss the last value of array

We use this package to get the whole range of IPs, but the last IP of array is always missed.

We use it like this to get the whole range, but I guess the last value should be included by default:
const ips = [...cidr.toArray({from: cidr.start(), to: cidr.end()}), cidr.end()];

Your type definition for typescript is not working

By reading the javascript implementation

class IPCIDR {
  constructor(cidr) {
  ...
}

You are expecting a class. Though, in the type definition you are exporting an interface with a constructor.

declare namespace ipcidr {
  ...
  interface IPCIDR {
        constructor(cidr: string): IPCIDR;
        ...
  }
}

How is this supposed to work?

Vulnerable to octal input data similar to CVE-2021-28918

Hi there,

auditing a different app using your library, I checked with an exploitation primitive described in a recent issue of the package netmask (see also security advisory).

Using IP addresses with octal format, it'd be possible to confuse e.g. your method contains, returning true for an IP address actually pointing to 8.1.1.1 (not belonging to 10.0.0.0/8 in this example).

ipcidr_octal

This could (and does in case of the unmentioned app affected) lead to bypassing of security checks based on IP addresses.

addressEnd and addressStart properties have incorrect subnetMask values

Hi man. Thanks for your work! Not a critical issue, but still :)

Take a look on addressStart and addressEnd values, they have incorrect .subnetMask property which differs from the one of address object

IPCIDR {
  _isValid: true,
  cidr: '10.10.0.0/30',
  ipAddressType:
   { [Function: Address4]
     fromHex: [Function],
     fromInteger: [Function],
     fromBigInteger: [Function] },
  address:
   Address4 {
     valid: true,
     address: '10.10.0.0/30',
     groups: 4,
     v4: true,
     subnet: '/30',
     subnetMask: 30,
     parsedSubnet: '30',
     addressMinusSuffix: '10.10.0.0',
     parsedAddress: [ '10', '10', '0', '0' ] },
  addressStart:
   Address4 {
     valid: true,
     address: '10.10.0.0',
     groups: 4,
     v4: true,
     subnet: '/32',
     subnetMask: 32,
     addressMinusSuffix: '10.10.0.0',
     parsedAddress: [ '10', '10', '0', '0' ] },
  addressEnd:
   Address4 {
     valid: true,
     address: '10.10.0.3',
     groups: 4,
     v4: true,
     subnet: '/32',
     subnetMask: 32,
     addressMinusSuffix: '10.10.0.3',
     parsedAddress: [ '10', '10', '0', '3' ] } }

Returned BigIntegers do not pass `instanceOf BigInteger`

> const IPCIDR = require("ip-cidr");
> const {BigInteger} = require("jsbn");
> (new IPCIDR("::/0")).start({type: "bigInteger"}) instanceof BigInteger
false

Any idea why those do not pass this instanceof check? I'm currently using val.constructor.name === 'BigInteger' to workaround but this method doesn't play well with minifiers which often mangle function names.

Feature Request: getCIDR

I would like the ability to get a list of CIDRs from a start and end IP address.

Is this something you're open to adding to the library?

`toArray` call triggers crash

Calling toArray simply crashes my app. I'm sorry I don't have more info than that but the whole thing crashes/locks up before any errors are thrown.

  • ip-cidr: 2.0.13
  • node: 13.8.0
  • OSX 10.15.5

IP Range to CIDR

Would be nice to have a method to convert IP range to CIDR.

Something like

const cidr = IPCIDR.fromRange('255.255.255.0', '255.255.255.255')
cidr instanceof IPCIDR // true
cidr.cidr // 255.255.255.128/24

IP address notation only is passing validation check

Hi @ortexx ,

First of all thank you for this handy tool! Unfortunately I run into an issue:

The isValid() function allows an IP address notation without CIDR to pass as valid CIDR. I know the underlying lib is ip-address and you use that for validation, but just an IP is not considered valid CIDR notation. Please check this RFC at IETF:

"In CIDR notation, a prefix is shown as a 4-octet quantity, just like a traditional IPv4 address or network number, followed by the "/" (slash) character, followed by a decimal value between 0 and 32 that describes the number of significant bits."

Am I using the validation function wrong maybe? I'm relatively new to programming so I'm not ruling that out :)

const cidr = new IPCIDR('192.168.4.1');
return cidr.isValid();

The above returns true in my situation. Can you advise on this please? I'm on version 2.0.13. Thank you!

Missing method/property count of the IPs

Missing method/property count of the IPs of the CIDR without generating the array.

Expecting something like

const cidr = new IPCIDR('255.255.255.128/24')
cidr.size // 256 (without generating the array cidr.toArray().length)
// or
cide.length // 256

Properties are not defined in the typings

ip-cidr/dist/ip-cidr.js

Lines 14 to 20 in bfff047

this.cidr = address.address;
this.ipAddressType = address.constructor;
this.address = address;
this.addressStart = address.startAddress();
this.addressEnd = address.endAddress();
this.addressStart.subnet = this.addressEnd.subnet = this.address.subnet;
this.addressStart.subnetMask = this.addressEnd.subnetMask = this.address.subnetMask;

None of these properties exist on the typings. Only the class-level methods.

image

.toArray() method is getting failed !

index.js -> toArray() method is getting failed in for loop for set of inputs.
e.g. -
I/P -> options = {from: 1500, limit: 600 } O/P -> array length = 600
I/P -> options = {from: 600, limit: 1200 } O/P -> array length = 0

On debugging, I noticed the following code snippet is getting failed due to incorrect comparison of jsbn BigInteger object with in for loop statements.

for (let i = info.from; i < info.from.add(info.to.compareTo(info.from)); i++) {
let num = start.add(new BigInteger(i + ''));
let ip = this.formatIP(this.ipAddressType.fromBigInteger(num), options);
list.push(ip);
}

e.g. ->

a = new BigInteger('600');
b = new BigInteger('1200');
console.log(a < b)); // returns false

Support ES6 module loading

Add an ES6 module version of ip-cidr to prevent messages like:

WARNING in component.ts depends on 'ip-cidr'. CommonJS or AMD dependencies can
cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies

Maybe create an additional .js file containing lines similar to:

import { ipAddress } from 'ip-address';
import { BigInteger } from 'jsbn';
...
export { IPCIDR };

promise.add is not a function

I need to get all the IPV6 inside the IPV6 start and IPV6 end range, using cidr.arrayAction(fn, options) but I get that error.

Can you explain how to use options with your functions?

Cannot install the package ip-cidr

I am not able to install package Ip-cidr

Node version: v8.10.0
Npm version: 3.5.2

Error message
`loadDep:ip-address → 304 ▐ ╢███████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
npm ERR! Linux 4.15.0-91-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "i" "ip-cidr"
npm ERR! node v8.10.0
npm ERR! npm v3.5.2
npm ERR! code EMISSINGARG

npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror http://github.com/npm/npm/issues

npm ERR! Please include the following file with any support request:
npm ERR! /home/omkar/Documents/Sprints/cb-azure-catalog-int/npm-debug.log`

npm-debug.log

Negative Testing with 10.10.10.0

Hello,

I am using ip-cidr for a Node.js package. While negative testing my package, I initialized an ip-cidr object with a dotted-quad-decimal IP address '10.10.10.0' instead of a CIDR '10.10.10.0/24'. I was expecting my object's isValid() method to return false, but it returns true.

I see that ip-cidr is relying on the ip-address npm package to determine if a valid address is present. Since a CIDR could be considered a subset of valid IP addresses, is this the intended behavior? If a subnet mask isn't passed, does ip-cidr infer a default mask?

Thanks,
Andrew Austin

IPCIDR may be not compatible with isValidAddress

Not sure if this is expected but IPCIDR.isValidAddress is not enough to ensure new IPCIDR will pass always.

IPCIDR.isValidAddress('50.165.190.0') // true
new IPCIDR('50.165.190.0')
// Thrown:
// Error: Invalid CIDR address.
//    at new IPCIDR (/private/tmp/node_modules/ip-cidr/index.js:9:13)

If isValidAddress is meant only for IP the address without the mask, then would be nice to have isValidCIDRAddress as well.

Provide TypeScript Types

This package seems pretty simple, I'd be glad to contribute some TypeScript definitions to add the project!

jest + 4.0.1 version issues. SyntaxError: Cannot use import statement outside a module

After upgrading the library to version 4.0.1 there is an issue on our jest execution.

  • in case nothing is done or apply on our side
    SyntaxError: Cannot use import statement outside a module

    > 3 | import IPCIDR from 'ip-cidr';
  • in case library is added to transformIgnorePatterns, like transformIgnorePatterns: ['<rootDir>/node_modules/(?!(ip-cidr)/)',], the Address4 is not found due to import ipAddress from 'ip-address'; is a problem
    TypeError: Cannot read properties of undefined (reading 'Address4')

      833 |   const erroredSubnets: ErroredSubnet[] = [];
      834 |
    > 835 |   const startingIP = (cidr: string) => new IPCIDR(cidr).start().toString();
          |                                        ^
      836 |
      837 |   const compareCidrs = (shouldInclude: boolean) => {
      838 |     if (shouldInclude) {

      at Function.Address4 [as createAddress] (node_modules/ip-cidr/index.js:179:71)
      at new createAddress (node_modules/ip-cidr/index.js:11:38)
  • in case dist file is used from moduleNameMapper like '^ip-cidr$': '<rootDir>/node_modules/ip-cidr/dist/ip-cidr.js',
    TypeError: ip_cidr_1.default is not a constructor

      833 |   const erroredSubnets: ErroredSubnet[] = [];
      834 |
    > 835 |   const startingIP = (cidr: string) => new IPCIDR(cidr).start().toString();

to mock the library was the only solution I found for being able to upgrade, like

class IPCIDR {
  address: string;

  constructor(address: string) {
    this.address = address;
  }

  start = () => this.address.split('/')[0];
}

export default IPCIDR;

and then '^ip-cidr$': '<rootDir>/__mocks__/ip-cidr-mock.ts', added to moduleNameMapper but this is not the right solution and could be very problematic in the future.

I guess library should be adapted to properly import ip-address library, right?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.