Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "range_check in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'range_check' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

const test = function(ctx, contentObj, callback) {
  // Don't bother with non-link content items
  if (contentObj.resourceSubType === 'link') {
    const { link } = contentObj;
    // Only allow HTTP(S) URLs
    if (/^http(s)?:\/\//.test(link)) {
      // Don't generate previews for internal IPs
      if (!rangeCheck.inRange(link.slice(link.lastIndexOf('://') + 1), PreviewConstants.FORBIDDEN.INTERNAL_IPS)) {
        // Default to the lowest possible score
        return callback(null, 1);
      }
    }
  }

  return callback(null, -1);
};
const test = function(ctx, contentObj, callback) {
  // Don't bother with non-link content items
  if (contentObj.resourceSubType === 'link') {
    const { link } = contentObj;
    // Only allow HTTP(S) URLs
    if (/^http(s)?:\/\//.test(link)) {
      // Don't generate previews for internal IPs
      if (
        !rangeCheck.inRange(
          link.slice(link.lastIndexOf('://') + 1),
          PreviewConstants.FORBIDDEN.INTERNAL_IPS
        )
      ) {
        // Default to the lowest possible score
        return callback(null, 1);
      }
    }
  }
  return callback(null, -1);
};
return range_check.validRange(ipRange);
		});

		if (allowedRanges.length <= 0) {
			throw new Error('No valid CIDR ranges were specified');
		}

		// Using req.ips requires that express 'trust proxy' setting is
		// true. When it *is* set the value for ips is extracted from the
		// X-Forwarded-For request header. The originating IP address is
		// the last one in the array.
		var requestIP = (req.ips.length > 0) ? req.ips.slice().pop() : req.ip;

		// Deny the request if request IP is not in one of the allowed
		// IP address ranges.
		var requestAllowed = range_check.inRange(requestIP, allowedRanges);

		if (!requestAllowed) {
			var msg = '-> blocked request from %s (not in allowed IP range)';
			console.log(util.format(msg, req.ip));
			// Display error page to the user.
			var title = 'Sorry, your request is not authorized (403)';
			var message = 'Requests from outside permitted IP range are not allowed';
			var htmlError = wrapHTMLError(title, message);

			return res.status(403).send(htmlError);
		}

		next();

	};
User.findById(id, function (err, user) {
      if (!err) {
         if (user) {
           if (user.allowAccess('Admin')) {
             // check for IP Range
             if (!range_check.in_range(req.connection.remoteAddress, config.adminIPRange)) {
       //        console.log("IP Address " + req.connection.remoteAddress + " is not within the allowed range(s).")
               return next(new restify.NotAuthorizedError("Access restricted."));
             }
           }
            return next({});
         } else {
            return next(new restify.NotAuthorizedError("Access restricted."));
         }
      } else {
         return next(new restify.NotAuthorizedError("Access restricted."));
      }
   });
  } else {
const testIp = function(ip, mode) {
    const constraint = this

    // Check if it is an array or a string
    if (typeof constraint === 'string') {
      if (rangeCheck.validRange(constraint)) {
        return testCidrBlock(ip, constraint, mode)
      } else {
        return testExplicitIp(ip, constraint, mode)
      }
    }

    if (typeof constraint === 'object') {
      return testRange(ip, constraint, mode)
    }
  }
let returnData = [];
                for (let i=0; i < data.length; i++) {
                    if (matcher.contains(data[i]['value'])) {
                        returnData.push(data[i]);
                    }
                }
                if (req.query.hasOwnProperty('count')) {
                    res.status(200).json({'count': returnData.length});
                } else {
                    res.status(200).json(returnData);
                }
                return;
            });
            return;
        } else if (req.query.hasOwnProperty('ipv6_range')) {
                if (!rangeCheck.isRange(req.query.ipv6_range)) {
                    res.status(400).json({'message': 'A valid IPv6 range must be provided'});
                    return;
                }
                let searchRange = req.query.ipv6_range.split(":")[0];
                promise = allDNS.getAllDNSByIPv6RangePromise(searchRange, source);
                promise.then(function(data) {
                    if (!data) {
                        res.status(404).json({'message': 'Info not found'});
                        return;
                    }
                    let returnData = [];
                    for (let i=0; i < data.length; i++) {
                        if (rangeCheck.inRange(data[i]['value'], req.query.ipv6_range)) {
                            returnData.push(data[i]);
                        }
                    }
validator.ipRanges = function(ipRanges) {
	var rangeCheck = require('range_check')
	   ,i , current
	   ,invalidIps = []
	;

	for (i = 0; i < ipRanges.length; i++) {
		current = ipRanges[i].split('/');
		if ( !rangeCheck.valid_ip(current[0]) ) {
			invalidIps.push('"'+current[0]+'"');
		}

		if ( current[1] && (current[1] < 17 || current[1] > 32) ) {
			invalidIps.push('"/'+ current[1]+'"');
		}
	}

	return invalidIps.length ? new Error('Invalid IPs/ranges: '+ invalidIps.join(', ')) : true;
};
function ip_range_matches() {
        if( "ip_range_matches" in modification_rule ) {
            for( var i = 0; i < modification_rule.ip_range_matches.length; i++ ) {
                if( rangeCheck.inRange( request.address.address, modification_rule.ip_range_matches[i] ) ) {
                    return true;
                }
            }
        } else {
            return true;
        }
        return false;
    }
function ensureInternalAccess (req, res, next) {
  let ip = req.ip || req.connection.remoteAddress || req.socket.remoteAddress || req.connection.socket.remoteAddress
  ip = ip.replace('::ffff:', '')
  let serverIp = ipLib.address('public', 'ipv4')
  if (ip === serverIp || (rangeCheck.validIp(ip) && rangeCheck.inRange(ip, config.internal_ip))) {
    next()
  } else {
    logger.warn(ip, 'is not an internal ip. Access denied')
    res.end()
  }
}
const testCidrBlock = (ip, constraint, mode) => {
    if (rangeCheck.inRange(ip, constraint)) {
      return mode === 'allow'
    } else {
      return mode === 'deny'
    }
  }

Is your System Free of Underlying Vulnerabilities?
Find Out Now