Skip to content

Commit

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

AF-123 regex tactic technique refs
  • Loading branch information
mikecarenzo committed Jul 20, 2023
2 parents d3682a6 + 42c4530 commit 4e75a18
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/attack_flow_builder/src/assets/builder.config.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class AttackFlowValidator extends DiagramValidator {

protected graph?: GraphExport;

static STIXregex = /^(?:[a-z][a-z0-9-]+[a-z0-9]--[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|null)$/i

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

// Additional validation for reference-based (tactic_ref + technique_ref) properties
if(key === "tactic_ref" && !AttackFlowValidator.STIXregex.test(String(value))) {
this.addError(id, "Invalid STIX tactic reference.");
} else if (key === "technique_ref" && !AttackFlowValidator.STIXregex.test(String(value))) {
this.addError(id, "Invalid STIX technique reference.");
}
// Additional validation for network address properties
if (node.template.id == "ipv4_addr" && !AttackFlowValidator.IPv4regex.test(String(value))) {
else 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))) {
} 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))) {
} else if (node.template.id === "mac_addr" && !AttackFlowValidator.MACregex.test(String(value))) {
this.addError(id, "Invalid MAC address.");
}
}
Expand Down

0 comments on commit 4e75a18

Please sign in to comment.