@mitre-attack/attack-data-model
Version:
A TypeScript API for the MITRE ATT&CK data model
159 lines (156 loc) • 6.95 kB
JavaScript
import {
stixIdentifierSchema
} from "./chunk-OM2DJ5DL.js";
// src/schemas/common/common-properties.ts
import { z } from "zod/v4";
var versionSchema = z.string().regex(/^\d+\.\d+$/, "Version must be in the format 'major.minor'").default("2.1").meta({
description: "Represents the version of the object in a 'major.minor' format, where both 'major' and 'minor' are integers. This versioning follows semantic versioning principles but excludes the patch number. The version number is incremented by ATT&CK when the content of the object is updated. This property does not apply to relationship objects."
});
var nameSchema = z.string().min(1, "Name must not be empty").meta({ description: "The name of the object." });
var descriptionSchema = z.string().meta({ description: "A description of the object." });
var aliasesSchema = z.array(z.string(), { error: "Aliases must be an array of strings." }).meta({
description: "Alternative names used to identify this object. The first alias must match the object's name."
});
var xMitreVersionSchema = z.string().regex(/^(\d{1,2})\.(\d{1,2})$/, "Version must be in format 'M.N' where M and N are 0-99").meta({
description: "Represents the version of the object in a 'major.minor' format, where both 'major' and 'minor' are integers between 0 and 99. This versioning follows semantic versioning principles but excludes the patch number. The version number is incremented by ATT&CK when the content of the object is updated. This property does not apply to relationship objects."
});
var semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
var xMitreAttackSpecVersionSchema = z.string().regex(semverRegex, "Must be valid semantic version (MAJOR.MINOR.PATCH)").meta({
description: "The version of the ATT&CK spec used by the object. This field helps consuming software determine if the data format is supported. If the field is not present on an object, the spec version will be assumed to be 2.0.0. Refer to the ATT&CK CHANGELOG for all supported versions."
});
var oldAttackIdRegex = /^MOB-(M|S)\d{4}$/;
function createOldMitreAttackIdSchema(stixType) {
const baseSchema = z.string().meta({ description: "Old ATT&CK IDs that may have been associated with this object" });
switch (stixType) {
case "malware":
case "tool":
return baseSchema.refine(
(value) => {
return /^MOB-S\d{4}$/.test(value);
},
{
message: `x_mitre_old_attack_id for ${stixType} need to be in the format MOB-S####`
}
);
case "course-of-action":
return baseSchema.refine(
(value) => {
return /^MOB-M\d{4}$/.test(value);
},
{
message: `x_mitre_old_attack_id for ${stixType} need to be in the format MOB-M####`
}
);
default:
throw new Error(`Unsupported STIX type: ${stixType}`);
}
}
var xMitreOldAttackIdSchema = z.string().refine(
(value) => {
return oldAttackIdRegex.test(value);
},
{
message: "Must be in the format 'MOB-X0000' where X is either 'M' or 'S', followed by exactly four digits"
}
).meta({ description: "Old ATT&CK IDs that may have been associated with this object" });
var attackDomainSchema = z.enum(["enterprise-attack", "mobile-attack", "ics-attack"]);
var xMitreDomainsSchema = z.array(attackDomainSchema).min(1, {
message: "At least one MITRE ATT&CK domain must be specified."
}).meta({ description: "The technology domains to which the ATT&CK object belongs." });
var xMitreDeprecatedSchema = z.boolean({
error: "x_mitre_deprecated must be a boolean."
}).meta({ description: "Indicates whether the object has been deprecated." });
var supportedMitrePlatforms = [
"Field Controller/RTU/PLC/IED",
"Network Devices",
"Data Historian",
"Google Workspace",
"Office Suite",
"ESXi",
"Identity Provider",
"Containers",
"Azure AD",
"Engineering Workstation",
"Control Server",
"Human-Machine Interface",
"Windows",
"Linux",
"IaaS",
"None",
"iOS",
"PRE",
"SaaS",
"Input/Output Server",
"macOS",
"Android",
"Safety Instrumented System/Protection Relay",
"Embedded"
];
var xMitrePlatformSchema = z.enum(supportedMitrePlatforms, {
error: () => `Platform must be one of: ${supportedMitrePlatforms.join(", ")}`
});
var xMitrePlatformsSchema = z.array(xMitrePlatformSchema, {
error: (issue) => issue.code === "invalid_type" ? "x_mitre_platforms must be an array of strings" : "Invalid platforms array"
}).min(1, "At least one platform is required").refine((items) => new Set(items).size === items.length, {
message: "Platforms must be unique (no duplicates allowed)."
}).meta({ description: "List of platforms that apply to the object." });
var objectMarkingRefsSchema = z.array(
stixIdentifierSchema.startsWith(
"marking-definition--",
'Identifier must start with "marking-definition--"'
)
).meta({
description: "The list of marking-definition objects to be applied to this object."
});
var xMitreContributorsSchema = z.array(z.string().nonempty()).meta({
description: "People and organizations who have contributed to the object. Not found on objects of type `relationship`."
}).nonempty();
var xMitreIdentity = "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5";
var xMitreIdentitySchema = z.literal(xMitreIdentity);
var xMitreModifiedByRefSchema = xMitreIdentitySchema.meta({
description: "The STIX ID of the MITRE identity object. Used to track the identity of the MITRE organization, which created the current version of the object. Previous versions of the object may have been created by other individuals or organizations."
});
var killChainNameSchema = z.enum([
"mitre-attack",
"mitre-mobile-attack",
"mitre-ics-attack"
]);
var killChainPhaseSchema = z.object({
phase_name: z.string({
error: (issue) => issue.input === void 0 ? "Phase name is required" : "Phase name must be a string"
}).refine(
(value) => {
const isLowercase = value === value.toLowerCase();
const usesHyphens = !value.includes(" ") && !value.includes("_");
return isLowercase && usesHyphens;
},
{
message: "Phase name should be all lowercase and use hyphens instead of spaces or underscores."
}
).meta({
description: "The name of the phase in the kill chain. The value of this property SHOULD be all lowercase and SHOULD use hyphens instead of spaces or underscores as word separators."
}),
kill_chain_name: killChainNameSchema
}).strict();
export {
versionSchema,
nameSchema,
descriptionSchema,
aliasesSchema,
xMitreVersionSchema,
xMitreAttackSpecVersionSchema,
createOldMitreAttackIdSchema,
xMitreOldAttackIdSchema,
attackDomainSchema,
xMitreDomainsSchema,
xMitreDeprecatedSchema,
xMitrePlatformSchema,
xMitrePlatformsSchema,
objectMarkingRefsSchema,
xMitreContributorsSchema,
xMitreIdentity,
xMitreIdentitySchema,
xMitreModifiedByRefSchema,
killChainNameSchema,
killChainPhaseSchema
};