Sha256: 4a0ee37351aabd3e5120590f0b062f1eb03e9fd0a8046454b0ac38a8a6ae18a3
Contents?: true
Size: 967 Bytes
Versions: 41
Compression:
Stored size: 967 Bytes
Contents
# frozen_string_literal: true require 'ipaddr' class MiniDefender::Rules::Ipv6 < MiniDefender::Rule MODES = %w[any public private] def initialize(mode = 'any') raise ArgumentError, 'Invalid mode' unless MODES.include?(mode) @mode = mode end def self.signature 'ipv6' end def self.make(args) new(args[0] || 'any') end def passes?(attribute, value, validator) ip = IPAddr.new(value.to_s) ip.ipv6? && ( @mode == 'any' || @mode == 'private' && (ip.private? || ip.link_local? || ip.loopback?) || @mode == 'public' && !(ip.private? || ip.link_local? || ip.loopback?) ) rescue IPAddr::InvalidAddressError false end def message(attribute, value, validator) case @mode when 'public' "The value must be a valid public IPv6 address." when 'private' "The value must be a valid private IPv6 address." else "The value must be a valid IPv6 address." end end end
Version data entries
41 entries across 41 versions & 1 rubygems