Skip to content

Commit

Permalink
Merge pull request #78 from center-for-threat-informed-defense/AF-124…
Browse files Browse the repository at this point in the history
…_regex_network_addresses

AF-124 IPv4, IPv6, & MAC regex check
  • Loading branch information
mikecarenzo committed Jul 18, 2023
2 parents 57d6524 + 8741133 commit ca3fa41
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/attack_flow_builder/src/assets/builder.config.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {

class AttackFlowValidator extends DiagramValidator {

static IPv4regex = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[0-9]))?$/;
static IPv6regex = /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?(\/(12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))?$/i;
static MACregex = /^([0-9a-f]{2}[:]){5}([0-9a-f]{2})$/i;

/**
* Validates a diagram.
* @param diagram
Expand Down Expand Up @@ -54,6 +58,15 @@ class AttackFlowValidator extends DiagramValidator {
// Validate properties
for (const [key, value] of node.props.value) {
this.validateProperty(id, key, value)

// Additional validation for network address properties
if (node.template.id == "ipv4_addr" && !AttackFlowValidator.IPv4regex.test(String(value))) {
this.addError(id, "Invalid IPv4 address.");
} else if (node.template.id == "ipv6_addr" && !AttackFlowValidator.IPv6regex.test(String(value))) {
this.addError(id, "Invalid IPv6 address.");
} else if (node.template.id == "mac_addr" && !AttackFlowValidator.MACregex.test(String(value))) {
this.addError(id, "Invalid MAC address.");
}
}
// Validate links
switch(node.template.id) {
Expand Down

0 comments on commit ca3fa41

Please sign in to comment.