Skip to content

Commit

Permalink
Merge pull request #86 from center-for-threat-informed-defense/af149-…
Browse files Browse the repository at this point in the history
…opinion

Af149 opinion
  • Loading branch information
mikecarenzo committed Jul 24, 2023
2 parents 2ba3ce4 + 3f39c88 commit dc9448c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 27 deletions.
14 changes: 12 additions & 2 deletions src/attack_flow_builder/src/assets/builder.config.publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,15 @@ class AttackFlowPublisher extends DiagramPublisher {
throw new Error("Basic dictionaries cannot contain dictionaries.");
case PropertyType.Enum:
if (prop instanceof EnumProperty && prop.isDefined()) {
let value = prop.toReferenceValue()!.toRawValue()!;
node[key] = value === "True";
let value = prop.toRawValue()!;
if(["true", "false"].includes(value.toString())) {
// case(BoolEnum)
node[key] = value === "true";
}
else {
// case(String | List | Dictionary | null)
node[key] = value;
}
}
break;
case PropertyType.List:
Expand Down Expand Up @@ -331,6 +338,9 @@ class AttackFlowPublisher extends DiagramPublisher {
case "note":
this.tryEmbedInNote(parent, c.obj);
break;
case "opinion":
this.tryEmbedInNote(parent, c.obj);
break;
case "report":
this.tryEmbedInNote(parent, c.obj);
break;
Expand Down
16 changes: 15 additions & 1 deletion src/attack_flow_builder/src/assets/builder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,21 @@ const config: AppConfiguration = {
properties: {
explanation : { type: PropertyType.String, is_primary: true },
authors : { type: PropertyType.List, form: { type: PropertyType.String } },
opinion : { type: PropertyType.String, is_required: true },
opinion : {
type: PropertyType.Enum,
options: {
type: PropertyType.List,
form: { type: PropertyType.String },
value: [
["strongly-disagree", "Strongly Disagree"],
["disagree", "Disagree"],
["neutral", "Neutral"],
["agree", "Agree"],
["strongly-agree", "Strongly Agree"]
]
},
is_required: true
}
},
anchor_template: "@__builtin__anchor",
style: DarkTheme.DictionaryBlock({ head: { ...Colors.Gray }})
Expand Down
49 changes: 27 additions & 22 deletions src/attack_flow_builder/src/assets/builder.config.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,32 @@ class AttackFlowValidator extends DiagramValidator {
}
// Validate links
switch(node.template.id) {
case "email_address": // Additional validation for email addresses
if (!AttackFlowValidator.Emailregex.test(String(node.props.value.get("value")))) {
this.addError(id, "Invalid email address.")
}
break;
case "grouping":
if(node.next.length === 0) {
this.addError(id, "A Grouping must point to at least one object.");
}
break;
break;
case "location": // Additional validation for location object
const region = node.props.value.get("region");
const country = node.props.value.get("country");
const latitude = node.props.value.get("latitude");
const longitude = node.props.value.get("longitude");

// Verify one of the required properties is set
if(!region?.isDefined() && !country?.isDefined() && !(latitude?.isDefined() || longitude?.isDefined())) {
this.addError(id, "Location requires one of the following properties: Region, Country, Latitude+Longitude.");
}

// Latitude + Longitude check
if(latitude?.isDefined() !== longitude?.isDefined()) {
this.addError(id, "Latitude and Longitude must be supplied together.");
}
break;
case "network_traffic":
this.validateNetworkTrafficLinks(id, node);
break;
Expand All @@ -164,6 +185,11 @@ class AttackFlowValidator extends DiagramValidator {
this.addError(id, "A Note must point to at least one object.");
}
break;
case "opinion":
if(node.next.length === 0) {
this.addError(id, "An Opinion must point to at least one object.");
}
break;
case "report":
if(node.next.length === 0) {
this.addError(id, "A Report must point to at least one object.");
Expand All @@ -174,27 +200,6 @@ class AttackFlowValidator extends DiagramValidator {
this.addError(id, "Invalid Windows registry key.");
}
break;
case "email_address": // Additional validation for email addresses
if (!AttackFlowValidator.Emailregex.test(String(node.props.value.get("value")))) {
this.addError(id, "Invalid email address.")
}
break;
case "location": // Additional validation for location object
const region = node.props.value.get("region");
const country = node.props.value.get("country");
const latitude = node.props.value.get("latitude");
const longitude = node.props.value.get("longitude");

// Verify one of the required properties is set
if(!region?.isDefined() && !country?.isDefined() && !(latitude?.isDefined() || longitude?.isDefined())) {
this.addError(id, "Location requires one of the following properties: Region, Country, Latitude+Longitude.");
}

// Latitude + Longitude check
if(latitude?.isDefined() !== longitude?.isDefined()) {
this.addError(id, "Latitude and Longitude must be supplied together.");
}
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export class ListProperty extends CollectionProperty {
// Create property
let prop = Property.create(this, descriptor.form, value);
// Add property
this.value.set(MD5(id), prop);
this.value.set(id, prop);
}
} else {
for(let id in descriptor.value) {
// Create property
let value = descriptor.value[id];
let prop = Property.create(this, descriptor.form, value);
// Add property
this.value.set(MD5(id), prop);
this.value.set(id, prop);
}
}
}
Expand Down

0 comments on commit dc9448c

Please sign in to comment.