Skip to content

Latest commit

 

History

History
167 lines (127 loc) · 7.29 KB

File metadata and controls

167 lines (127 loc) · 7.29 KB

Enhanced Metadata Validator

The Enhanced Metadata Validator provides intelligent file type filtering and preprocessor-aware validation that analyzes metadata from various file types using type-specific patterns and confidence scoring.

Features

  • Intelligent File Type Filtering: Automatically determines which files can contain meaningful metadata and skips plain text files for improved performance
  • Preprocessor-Aware Validation: Applies different validation rules based on metadata source type
  • Content Routing: Automatically separates metadata from document body content
  • Type-Specific Patterns: Specialized detection patterns for image, document, audio, and video metadata
  • Enhanced Confidence Scoring: Includes preprocessor-specific confidence boosts and context awareness
  • Dual-Path Architecture: Metadata content routed exclusively to metadata validator, document content to other validators
  • Performance Optimization: 20-30% faster processing for workloads with many plain text files

File Type Filtering

The metadata validator automatically determines which files can contain meaningful metadata and optimizes processing accordingly:

Files Processed for Metadata

  • Images: .jpg, .jpeg, .png, .gif, .tiff, .tif, .bmp, .webp, .heic, .heif, .raw, .cr2, .nef, .arw
  • Documents: .pdf, .docx, .doc, .xlsx, .xls, .pptx, .ppt, .odt, .ods, .odp
  • Audio: .mp3, .flac, .wav, .ogg, .m4a, .aac, .wma, .opus
  • Video: .mp4, .mov, .avi, .mkv, .wmv, .flv, .webm, .m4v, .3gp, .ogv

Files Skipped for Performance

  • Plain Text: .txt, .md, .log, .csv, .json, .xml, .html
  • Source Code: .js, .py, .go, .java, .c, .cpp, .h, .sh, .bat, .ps1
  • Configuration: .yaml, .yml, .ini, .conf, .cfg
  • Unknown Extensions: Files without extensions or unrecognized types

Performance Benefits

  • 20-30% faster processing for workloads with many plain text files
  • Eliminates false positives from analyzing text content as metadata
  • Reduced resource usage through intelligent content routing
  • Maintains full accuracy for files that actually contain metadata

Supported Metadata Types

Image Metadata (EXIF, GPS, Device Info)

  • GPS coordinates and location data
  • Camera and device information
  • Creator and copyright information
  • Software paths containing usernames

Document Metadata (PDF, Office Documents)

  • Author and creator information
  • Document properties and comments
  • Rights and copyright information
  • Company and organizational data

Audio Metadata (MP3, FLAC, WAV, M4A)

  • Artist and performer information
  • Contact and management details
  • Recording location and venue data
  • Publisher and label information

Video Metadata (MP4, MOV, M4V)

  • GPS coordinates and location data
  • Recording device information
  • Creator and production details
  • Studio and production company data

Detection Capabilities

The enhanced validator provides preprocessor-aware detection with type-specific patterns:

Metadata Type Sensitive Fields Confidence Boosts Example Fields
Image GPS, Device, Creator GPS: +60%, Device: +40%, Creator: +30% GPSLatitude, Camera_Make, Artist
Document Author, Comments, Rights Manager: +40%, Comments: +50%, Author: +30% Author, LastModifiedBy, Comments
Audio Artist, Contact, Location Contact: +50%, Management: +40%, Artist: +30% Artist, Management, Venue
Video GPS, Device, Creator GPS: +60%, Location: +50%, Device: +40% GPSLatitude, RecordedBy, Studio

Enhanced Confidence Scoring

The validator uses a sophisticated multi-factor confidence scoring system:

Base Confidence Factors

  • Field Relevance: How relevant the field is to the preprocessor type
  • Pattern Strength: How well the content matches expected patterns
  • Context Indicators: Surrounding metadata that supports the match

Preprocessor-Specific Boosts

  • Type-Specific Adjustments: Confidence boosts based on metadata source type
  • Field Category Weighting: Different weights for GPS, device, creator, etc.
  • Context Awareness: Enhanced scoring based on preprocessor context

Confidence Levels

  • HIGH (90-100%): Very likely sensitive data with strong patterns and context
  • MEDIUM (60-89%): Possibly sensitive data with moderate confidence
  • LOW (0-59%): Likely false positive or low-confidence match

Usage

Basic Usage

// Create a new enhanced metadata validator
validator := metadata.NewEnhancedValidator()

// Validate metadata content with preprocessor context
metadataContent := MetadataContent{
    Content:          "GPSLatitude: 40.7128\nGPSLongitude: -74.0060",
    PreprocessorType: "image_metadata",
    SourceFile:       "photo.jpg",
}

matches, err := validator.ValidateMetadataContent(metadataContent)
if err != nil {
    log.Fatalf("Error validating metadata: %v", err)
}

// Process matches with enhanced information
for _, match := range matches {
    fmt.Printf("Found %s with confidence %.2f from %s\n",
        match.Type, match.Confidence, match.Metadata["source"])
}

Command Line Usage

# Scan image metadata with enhanced validation (automatically processes .jpg files)
ferret-scan --file photo.jpg --checks METADATA --verbose

# Debug content routing and validation decisions (shows file type filtering)
ferret-scan --file document.pdf --checks METADATA --debug

# Scan multiple metadata types with high confidence (automatically skips .txt, .py, .js files)
ferret-scan --file media/ --recursive --checks METADATA --confidence high

# Example showing file type filtering in mixed directory
ferret-scan --file mixed-folder/ --recursive --checks METADATA --debug
# Debug output will show:
# "Skipping metadata validation for script.py (plain text file type)"
# "Processing metadata for photo.jpg (image file type)"

Implementation Details

The enhanced validator works through a sophisticated dual-path architecture:

Content Routing Phase

  1. Content Separation: Content Router separates metadata from document body content
  2. Preprocessor Detection: Identifies the source preprocessor type for metadata content
  3. Context Preservation: Maintains preprocessor context throughout the validation process

Validation Phase

  1. Rule Selection: Applies type-specific validation rules based on preprocessor type
  2. Pattern Matching: Uses specialized patterns for each metadata type
  3. Confidence Calculation: Calculates base confidence and applies preprocessor-specific boosts
  4. Result Generation: Returns matches with enhanced metadata including source information

Architecture Benefits

  • Improved Accuracy: 20-30% improvement in precision through targeted validation
  • Reduced False Positives: 40-50% reduction through preprocessor-aware patterns and file type filtering
  • Enhanced Performance: 20-30% faster processing through intelligent file type filtering and content routing
  • Better Debugging: Detailed observability into validation decisions, file type filtering, and confidence scoring
  • Resource Optimization: Reduced memory usage and CPU consumption by skipping non-metadata files

Testing

Tests for the metadata validator can be found in metadata_validator_test.go. Run them with:

go test -v ./internal/validators/metadata