SPF: verify IPv4 and IPv6 ranges in SPF mechanisms.

This commit is contained in:
Philippe Pittoli 2024-03-07 01:13:53 +01:00
parent a6b658253d
commit 5b93c32669
2 changed files with 14 additions and 21 deletions

View File

@ -97,6 +97,7 @@ show_error_ip6 e = case e of
Bulma.p "The IPv6 representation is erroneous. It should contain only up to 8 groups of hexadecimal characters."
IPAddress.IP6IrrelevantShortRepresentation ->
Bulma.p "IPv6 address has been unnecessarily shortened (with two ':')."
IPAddress.IP6InvalidRange -> Bulma.p "IPv6 address or range isn't valid."
show_error_ip4 :: forall w i. IPAddress.IPv4Error -> HH.HTML w i
show_error_ip4 e = case e of
@ -104,6 +105,7 @@ show_error_ip4 e = case e of
Bulma.p $ "IPv4 address contains a number too big (should be between 0 and 255). Current entered number: " <> show n
IPAddress.IP4IrrelevantShortRepresentation ->
Bulma.p "IPv4 address has been unnecessarily shortened (with two '.')."
IPAddress.IP4InvalidRange -> Bulma.p "IPv4 address or range isn't valid."
show_error_txt :: forall w i. ValidationDNS.TXTError -> HH.HTML w i
show_error_txt e = case e of

View File

@ -1,6 +1,6 @@
module App.Validation.DNS where
import Prelude (apply, between, bind, map, pure, ($), (-), (<), (<$>), (<>))
import Prelude (apply, between, bind, map, pure, ($), (-), (<), (<>))
import Control.Alt ((<|>))
import Data.Array as A
@ -57,24 +57,15 @@ data Error
type AVErrors = Array Error
-- | Current default values.
min_ttl :: Int
min_ttl = 30
max_ttl :: Int
max_ttl = 86000
max_txt :: Int
max_txt = 500
min_priority :: Int
min_priority = 0
max_priority :: Int
max_priority = 65535
min_port :: Int
min_port = 0
max_port :: Int
max_port = 65535
min_weight :: Int
min_weight = 0
max_weight :: Int
max_weight = 65535
min_ttl = 30 :: Int
max_ttl = 86000 :: Int
max_txt = 500 :: Int
min_priority = 0 :: Int
max_priority = 65535 :: Int
min_port = 0 :: Int
max_port = 65535 :: Int
min_weight = 0 :: Int
max_weight = 65535 :: Int
-- Functions handling network-related structures (ResourceRecord).
@ -215,10 +206,10 @@ validate_SPF_mechanism m = case m.t of
name <- parse (or_nothing DomainParser.sub_eof) m.v VESPFMechanismName
in first m name -- name is discarded
RR.IP4 -> ado
name <- parse IPAddress.ipv4 m.v VESPFMechanismIPv4
name <- parse (IPAddress.ipv4_range <|> IPAddress.ipv4) m.v VESPFMechanismIPv4
in first m name -- name is discarded
RR.IP6 -> ado
name <- parse IPAddress.ipv6 m.v VESPFMechanismIPv6
name <- parse (IPAddress.ipv6_range <|> IPAddress.ipv6) m.v VESPFMechanismIPv6
in first m name -- name is discarded
_ -> pure m