
Security News
pnpm 11.5 Adds Support for Recognizing npm Staged Publishes
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.
@mitre/hdf-validators
Advanced tools
JSON Schema validation for HDF documents (Results and Baselines)
JSON Schema validation for Heimdall Data Format (HDF) documents. Validates all 7 HDF document types against their official schemas to ensure structural correctness and data integrity.
hdf-validators provides schema-based validation:
validate() function| hdf-validators | hdf-utilities |
|---|---|
| HDF schema validation | Format syntax validation |
| "Is this valid HDF?" | "Is this valid JSON/XML/CSV?" |
| "Does baselines exist and is it an array?" | "Can this string be parsed as JSON?" |
| Validates structure and types | Validates syntax only |
| HDF-specific semantic rules | Generic format handling |
Example:
isValidJSON('{"foo": "bar"}') → true (utilities - just checks JSON syntax)validateResults({foo: 'bar'}) → false, missing baselines field (validators - checks HDF schema)npm install @mitre/hdf-validators
import { validateResults, validateBaseline } from '@mitre/hdf-validators';
// Validate HDF Results
const hdfResults = {
baselines: [{
name: 'My Baseline',
checksum: { algorithm: 'sha256', value: 'abc123' },
requirements: [{
id: 'REQ-001',
descriptions: [{ label: 'default', data: 'Test requirement' }],
impact: 0.7,
tags: { nist: ['AC-1'] },
results: [{
status: 'passed',
codeDesc: 'Control check',
startTime: '2025-01-01T00:00:00Z'
}]
}]
}],
targets: [],
statistics: {}
};
const result = validateResults(hdfResults);
if (result.valid) {
console.log('✓ Valid HDF Results document');
} else {
console.error('✗ Validation failed:');
console.error(result.getErrorMessage());
// Or access individual errors
result.errors.forEach(error => {
console.error(` ${error.field}: ${error.message}`);
});
}
// Validate HDF Baseline
const hdfBaseline = {
name: 'Security Baseline',
title: 'Example Security Baseline',
version: '1.0.0',
checksum: { algorithm: 'sha256', value: 'def456' },
requirements: [{
id: 'REQ-001',
title: 'Access Control',
descriptions: [{ label: 'default', data: 'Requirement description' }],
impact: 0.7,
tags: { nist: ['AC-1', 'AC-2'] }
}]
};
const baselineResult = validateBaseline(hdfBaseline);
if (!baselineResult.valid) {
console.error('Validation errors:', baselineResult.errors);
}
// Auto-detect document type
import { validate } from '@mitre/hdf-validators';
const autoResult = validate(someHdfDocument);
// Automatically determines if it's Results or Baseline and validates accordingly
package main
import (
"encoding/json"
"fmt"
"os"
validators "github.com/mitre/hdf-libs/hdf-validators/go/v3"
)
func main() {
// Read HDF file
data, err := os.ReadFile("results.json")
if err != nil {
panic(err)
}
// Validate HDF Results
result := validators.ValidateResults(data)
if result.Valid {
fmt.Println("✓ Valid HDF Results document")
} else {
fmt.Println("✗ Validation failed:")
fmt.Println(result.Error())
// Access individual errors
for _, e := range result.Errors {
fmt.Printf(" %s: %s\n", e.Field, e.Description)
}
os.Exit(1)
}
}
// Validate HDF Baseline
result := validators.ValidateBaseline(baselineData)
// Use custom schema directory (for development/testing)
validators.SetSchemaDir("./custom-schemas")
result = validators.ValidateResults(data) // Will use schemas from custom directory
// Reset to embedded schemas
validators.SetSchemaDir("")
validateResults(data: unknown): ValidationResultValidate data against the HDF Results schema.
data - JavaScript object to validateValidationResult with validation status and errorsvalidateBaseline(data: unknown): ValidationResultValidate data against the HDF Baseline schema.
data - JavaScript object to validateValidationResult with validation status and errorsvalidateComparison(data: unknown): ValidationResultValidate data against the HDF Comparison schema.
data - JavaScript object to validateValidationResult with validation status and errorsvalidateSystem(data: unknown): ValidationResultValidate data against the HDF System schema.
data - JavaScript object to validateValidationResult with validation status and errorsvalidatePlan(data: unknown): ValidationResultValidate data against the HDF Plan schema.
data - JavaScript object to validateValidationResult with validation status and errorsvalidateAmendments(data: unknown): ValidationResultValidate data against the HDF Amendments schema.
data - JavaScript object to validateValidationResult with validation status and errorsvalidateEvidencePackage(data: unknown): ValidationResultValidate data against the HDF Evidence Package schema.
data - JavaScript object to validateValidationResult with validation status and errorsvalidate(data: unknown): ValidationResultAuto-detect document type and validate.
data - JavaScript object to validateValidationResult with validation status and errorsValidationResultinterface ValidationResult {
valid: boolean; // True if validation passed
errors: ValidationError[]; // Array of validation errors (empty if valid)
getErrorMessage(): string; // Formatted error message
}
ValidationErrorinterface ValidationError {
field: string; // JSON path to the field with error
message: string; // Description of the validation error
value?: unknown; // The invalid value (optional)
}
ValidateResults(data []byte) ValidationResultValidate JSON bytes against the HDF Results schema.
data - JSON bytes to validateValidationResult with validation status and errorsValidateBaseline(data []byte) ValidationResultValidate JSON bytes against the HDF Baseline schema.
data - JSON bytes to validateValidationResult with validation status and errorsValidate(data []byte, schemaType SchemaType) ValidationResultValidate JSON bytes against specified schema type.
data - JSON bytes to validateschemaType - TypeResults or TypeBaselineValidationResult with validation status and errorsSetSchemaDir(dir string)Configure package to load schemas from a directory instead of embedded schemas.
dir - Directory path (empty string to revert to embedded schemas)GetSchemaDir() stringGet the current schema directory (empty if using embedded schemas).
ValidationResulttype ValidationResult struct {
Valid bool `json:"valid"` // True if validation passed
Errors []ValidationError `json:"errors"` // Validation errors (empty if valid)
}
func (r ValidationResult) Error() string // Formatted error message
ValidationErrortype ValidationError struct {
Field string `json:"field"` // JSON path to invalid field
Description string `json:"description"` // Error description
Value any `json:"value"` // Invalid value (optional)
}
baselines: is required
HDF Results must have a baselines array.
baselines: must be array
baselines[0].name: is required
The name field is required for each baseline.
results[0].status: must be equal to one of the allowed values
Result status must be one of: passed, failed, error, notApplicable, notReviewed.
impact: must be >= 0 and <= 1
Impact scores must be between 0.0 and 1.0.
Validate that your converter produces valid HDF:
import { convertNessusToHdf } from '@mitre/hdf-converters';
import { validateResults } from '@mitre/hdf-validators';
const hdf = convertNessusToHdf(nessusXml);
const result = validateResults(JSON.parse(hdf));
if (!result.valid) {
throw new Error(`Invalid HDF output: ${result.getErrorMessage()}`);
}
Validate HDF before uploading to Heimdall:
const hdfData = JSON.parse(fs.readFileSync('scan-results.json', 'utf-8'));
const result = validateResults(hdfData);
if (result.valid) {
uploadToHeimdall(hdfData);
} else {
console.error('Cannot upload invalid HDF:', result.getErrorMessage());
}
# Validate HDF file in CI
hdf validate results.json
# Exit code 0 if valid, non-zero if invalid
if hdf validate scan.json --quiet; then
echo "✓ HDF validation passed"
else
echo "✗ HDF validation failed"
exit 1
fi
# Install dependencies
pnpm install
# Run TypeScript tests
pnpm test:ts
# Run Go tests
pnpm test:go
# Run all tests
pnpm test
# Run tests with coverage
pnpm test:coverage
# Build TypeScript package
pnpm build
# Lint code
pnpm lint
Both TypeScript and Go implementations maintain >95% test coverage with comprehensive validation tests covering:
Apache-2.0 © MITRE Corporation
FAQs
JSON Schema validation for HDF documents (Results and Baselines)
We found that @mitre/hdf-validators demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.