scoring

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 1, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AggregatorConfig

type AggregatorConfig struct {
	// Aggregation method
	WeightedCombination bool    `json:"weighted_combination"`
	ProximityWeight     float64 `json:"proximity_weight"`
	MLWeight            float64 `json:"ml_weight"`
	ValidationWeight    float64 `json:"validation_weight"`

	// Score bounds
	MaxScore float64 `json:"max_score"`
	MinScore float64 `json:"min_score"`

	// Risk level thresholds (aligned with Australian banking regulations)
	CriticalThreshold float64 `json:"critical_threshold"` // 0.9+
	HighThreshold     float64 `json:"high_threshold"`     // 0.7-0.89
	MediumThreshold   float64 `json:"medium_threshold"`   // 0.4-0.69

	// Regulatory compliance settings
	APRACompliance       bool `json:"apra_compliance"`
	PrivacyActCompliance bool `json:"privacy_act_compliance"`

	// Audit trail settings
	DetailedAuditTrail bool `json:"detailed_audit_trail"`
	IncludeTimestamps  bool `json:"include_timestamps"`
}

AggregatorConfig holds configuration for score aggregation

func DefaultAggregatorConfig

func DefaultAggregatorConfig() *AggregatorConfig

DefaultAggregatorConfig returns the default aggregator configuration

type AuditEntry

type AuditEntry struct {
	Component   string            `json:"component"`
	Timestamp   time.Time         `json:"timestamp"`
	Score       float64           `json:"score"`
	Description string            `json:"description"`
	Details     map[string]string `json:"details"`
}

AuditEntry represents a single audit trail entry for regulatory compliance

type CoOccurrence

type CoOccurrence struct {
	PIType   detection.PIType `json:"pi_type"`
	Distance int              `json:"distance"`
	Match    string           `json:"match"`
}

CoOccurrence represents other PI types found in proximity

type ComplianceAction

type ComplianceAction struct {
	Type        string    `json:"type"`
	Description string    `json:"description"`
	Priority    string    `json:"priority"`
	Deadline    time.Time `json:"deadline"`
}

ComplianceAction represents a required action for regulatory compliance

type ComplianceFlags

type ComplianceFlags struct {
	NotifiableDataBreach  bool     `json:"notifiable_data_breach"`
	APRAReporting         bool     `json:"apra_reporting"`
	PrivacyActBreach      bool     `json:"privacy_act_breach"`
	GDPRApplicable        bool     `json:"gdpr_applicable"`
	RequiredNotifications []string `json:"required_notifications"`
}

ComplianceFlags indicates regulatory compliance requirements

type ConfidenceEngine

type ConfidenceEngine struct {
	// contains filtered or unexported fields
}

ConfidenceEngine is the main engine responsible for calculating confidence scores by integrating multiple detection methods and providing risk-based scoring aligned with Australian banking regulations.

func NewConfidenceEngine

func NewConfidenceEngine(config *EngineConfig) (*ConfidenceEngine, error)

NewConfidenceEngine creates a new confidence scoring engine

func (*ConfidenceEngine) CalculateScore

func (e *ConfidenceEngine) CalculateScore(ctx context.Context, input ScoreInput) (*ConfidenceResult, error)

CalculateScore computes the confidence score for a given PI finding

func (*ConfidenceEngine) GetEngineInfo

func (e *ConfidenceEngine) GetEngineInfo() map[string]interface{}

GetEngineInfo returns information about the confidence engine

type ConfidenceResult

type ConfidenceResult struct {
	// Final score and risk assessment
	FinalScore float64   `json:"final_score"`
	RiskLevel  RiskLevel `json:"risk_level"`

	// Detailed breakdown
	Breakdown  ScoreBreakdown `json:"breakdown"`
	AuditTrail []AuditEntry   `json:"audit_trail"`

	// Regulatory compliance
	RegulatoryCompliance RegulatoryCompliance `json:"regulatory_compliance"`

	// Metadata
	CalculatedAt time.Time `json:"calculated_at"`
	Version      string    `json:"version"`
}

ConfidenceResult represents the final confidence scoring result

type EngineConfig

type EngineConfig struct {
	// Thresholds
	MinConfidenceThreshold float64 `json:"min_confidence_threshold"`
	MaxConfidenceThreshold float64 `json:"max_confidence_threshold"`

	// Integration settings
	EnableProximityScoring  bool `json:"enable_proximity_scoring"`
	EnableMLScoring         bool `json:"enable_ml_scoring"`
	EnableValidationScoring bool `json:"enable_validation_scoring"`

	// Australian regulatory compliance
	APRACompliance       bool `json:"apra_compliance"`
	PrivacyActCompliance bool `json:"privacy_act_compliance"`
	BankingRegCompliance bool `json:"banking_reg_compliance"`

	// Risk level thresholds (Australian banking aligned)
	CriticalThreshold float64 `json:"critical_threshold"` // 0.9+
	HighThreshold     float64 `json:"high_threshold"`     // 0.7-0.89
	MediumThreshold   float64 `json:"medium_threshold"`   // 0.4-0.69

	// Performance settings
	EnableAuditTrail      bool `json:"enable_audit_trail"`
	EnableDetailedLogging bool `json:"enable_detailed_logging"`
}

EngineConfig holds configuration for the confidence engine

func DefaultEngineConfig

func DefaultEngineConfig() *EngineConfig

DefaultEngineConfig returns the default configuration optimized for Australian PI detection

type ExposureCalculator

type ExposureCalculator struct {
	// contains filtered or unexported fields
}

ExposureCalculator calculates the exposure level of PI data

func NewExposureCalculator

func NewExposureCalculator(config *RiskMatrixConfig) *ExposureCalculator

NewExposureCalculator creates a new exposure calculator

func (*ExposureCalculator) Calculate

Calculate computes the exposure score and factors

type ExposureFactors

type ExposureFactors struct {
	RepositoryVisibility string  `json:"repository_visibility"`
	FileAccessibility    float64 `json:"file_accessibility"`
	DataLifetime         int     `json:"data_lifetime_days"`
	EncryptionStatus     string  `json:"encryption_status"`
	AccessControls       float64 `json:"access_controls"`
}

ExposureFactors represents factors contributing to exposure assessment

type FactorConfig

type FactorConfig struct {
	// Component weights for score calculation
	ProximityWeight  float64 `json:"proximity_weight"`
	MLWeight         float64 `json:"ml_weight"`
	ValidationWeight float64 `json:"validation_weight"`

	// Environment penalties/bonuses
	EnvironmentPenalties map[string]float64 `json:"environment_penalties"`
	EnvironmentBonuses   map[string]float64 `json:"environment_bonuses"`

	// Co-occurrence multipliers based on Australian PI risk combinations
	CoOccurrenceMultipliers map[string]map[string]float64 `json:"co_occurrence_multipliers"`

	// PI type weights aligned with Australian banking regulations
	PITypeWeights map[detection.PIType]float64 `json:"pi_type_weights"`

	// Distance decay factor for co-occurrences
	DistanceDecayFactor  float64 `json:"distance_decay_factor"`
	MaxCoOccurrenceBoost float64 `json:"max_co_occurrence_boost"`
}

FactorConfig holds configuration for factor calculations

func DefaultFactorConfig

func DefaultFactorConfig() *FactorConfig

DefaultFactorConfig returns the default factor configuration optimized for Australian PI detection

type FactorEngine

type FactorEngine struct {
	// contains filtered or unexported fields
}

FactorEngine calculates individual scoring factors for confidence assessment

func NewFactorEngine

func NewFactorEngine(config *FactorConfig) (*FactorEngine, error)

NewFactorEngine creates a new factor engine with the given configuration

func (*FactorEngine) CalculateCoOccurrenceFactor

func (e *FactorEngine) CalculateCoOccurrenceFactor(piType detection.PIType, coOccurrences []CoOccurrence) float64

CalculateCoOccurrenceFactor calculates the co-occurrence score factor

func (*FactorEngine) CalculateEnvironmentFactor

func (e *FactorEngine) CalculateEnvironmentFactor(filename, content string) float64

CalculateEnvironmentFactor calculates the environment-based score factor

func (*FactorEngine) CalculateMLFactor

func (e *FactorEngine) CalculateMLFactor(mlData *MLScore) float64

CalculateMLFactor calculates the machine learning score factor

func (*FactorEngine) CalculatePITypeWeight

func (e *FactorEngine) CalculatePITypeWeight(piType detection.PIType) float64

CalculatePITypeWeight calculates the weight factor based on PI type importance

func (*FactorEngine) CalculateProximityFactor

func (e *FactorEngine) CalculateProximityFactor(proximityData *ProximityScore) float64

CalculateProximityFactor calculates the proximity score factor

func (*FactorEngine) CalculateValidationFactor

func (e *FactorEngine) CalculateValidationFactor(validationData *ValidationScore) float64

CalculateValidationFactor calculates the algorithmic validation score factor

func (*FactorEngine) DetectEnvironmentIndicators

func (e *FactorEngine) DetectEnvironmentIndicators(filename, content string) []string

DetectEnvironmentIndicators detects environment-related indicators in filename and content

func (*FactorEngine) GetCoOccurrenceMultipliers

func (e *FactorEngine) GetCoOccurrenceMultipliers() map[string]map[string]float64

GetCoOccurrenceMultipliers returns all co-occurrence multipliers

func (*FactorEngine) GetEnvironmentPenalties

func (e *FactorEngine) GetEnvironmentPenalties() map[string]float64

GetEnvironmentPenalties returns all environment penalties

func (*FactorEngine) GetFactorWeights

func (e *FactorEngine) GetFactorWeights() map[string]float64

GetFactorWeights returns the configured factor weights

func (*FactorEngine) GetPITypeWeights

func (e *FactorEngine) GetPITypeWeights() map[detection.PIType]float64

GetPITypeWeights returns all PI type weights

type FactorScores

type FactorScores struct {
	ProximityScore    float64 `json:"proximity_score"`
	MLScore           float64 `json:"ml_score"`
	ValidationScore   float64 `json:"validation_score"`
	EnvironmentScore  float64 `json:"environment_score"`
	CoOccurrenceScore float64 `json:"co_occurrence_score"`
	PITypeWeight      float64 `json:"pi_type_weight"`
}

FactorScores holds the calculated scores for all factors

type FileContext

type FileContext struct {
	FilePath        string `json:"file_path"`
	FileSize        int64  `json:"file_size"`
	IsProduction    bool   `json:"is_production"`
	IsTest          bool   `json:"is_test"`
	IsConfiguration bool   `json:"is_configuration"`
	IsSource        bool   `json:"is_source"`
	Language        string `json:"language"`
}

FileContext contains file-specific context

type HistoricalData

type HistoricalData struct {
	PreviousIncidents int       `json:"previous_incidents"`
	LastIncidentDate  time.Time `json:"last_incident_date"`
	RemediationTime   int       `json:"avg_remediation_days"`
	FalsePositiveRate float64   `json:"false_positive_rate"`
}

HistoricalData contains historical incident information

type ImpactCalculator

type ImpactCalculator struct {
	// contains filtered or unexported fields
}

ImpactCalculator calculates the potential impact of a PI exposure

func NewImpactCalculator

func NewImpactCalculator(config *RiskMatrixConfig) *ImpactCalculator

NewImpactCalculator creates a new impact calculator

func (*ImpactCalculator) Calculate

Calculate computes the impact score and factors

type ImpactFactors

type ImpactFactors struct {
	DataSensitivity     float64 `json:"data_sensitivity"`
	RecordCount         int     `json:"record_count"`
	FinancialImpact     float64 `json:"financial_impact"`
	RegulatoryImpact    float64 `json:"regulatory_impact"`
	ReputationalImpact  float64 `json:"reputational_impact"`
	AffectedIndividuals int     `json:"affected_individuals"`
}

ImpactFactors represents factors contributing to impact assessment

type LikelihoodCalculator

type LikelihoodCalculator struct {
	// contains filtered or unexported fields
}

LikelihoodCalculator calculates the likelihood of PI exploitation

func NewLikelihoodCalculator

func NewLikelihoodCalculator(config *RiskMatrixConfig) *LikelihoodCalculator

NewLikelihoodCalculator creates a new likelihood calculator

func (*LikelihoodCalculator) Calculate

Calculate computes the likelihood score and factors

type LikelihoodFactors

type LikelihoodFactors struct {
	ExploitComplexity     float64 `json:"exploit_complexity"`
	AccessVector          string  `json:"access_vector"`
	Authentication        string  `json:"authentication"`
	HistoricalIncidents   int     `json:"historical_incidents"`
	ThreatActorCapability float64 `json:"threat_actor_capability"`
}

LikelihoodFactors represents factors contributing to likelihood assessment

type MLScore

type MLScore struct {
	Confidence float32 `json:"confidence"`
	PIType     string  `json:"pi_type"`
	IsValid    bool    `json:"is_valid"`
	ModelName  string  `json:"model_name,omitempty"`
}

MLScore represents machine learning model results

type Mitigation

type Mitigation struct {
	ID          string   `json:"id"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Priority    string   `json:"priority"`
	Effort      string   `json:"effort"`
	Timeline    string   `json:"timeline"`
	Category    string   `json:"category"`
	Compliance  []string `json:"compliance"`
}

Mitigation represents a recommended mitigation action

type OrganizationInfo

type OrganizationInfo struct {
	Industry        string `json:"industry"`
	Size            string `json:"size"`
	Regulated       bool   `json:"regulated"`
	HasSecurityTeam bool   `json:"has_security_team"`
	MaturityLevel   string `json:"maturity_level"`
}

OrganizationInfo contains organization context

type ProximityScore

type ProximityScore struct {
	Score    float64  `json:"score"`
	Context  string   `json:"context"`
	Keywords []string `json:"keywords"`
	Distance int      `json:"distance"`
}

ProximityScore represents proximity detection results

type RegulatoryCompliance

type RegulatoryCompliance struct {
	APRA            bool               `json:"apra_compliance"`
	PrivacyAct      bool               `json:"privacy_act_compliance"`
	RequiredActions []ComplianceAction `json:"required_actions"`
}

RegulatoryCompliance represents Australian regulatory compliance information

type RepositoryInfo

type RepositoryInfo struct {
	IsPublic      bool      `json:"is_public"`
	Stars         int       `json:"stars"`
	Forks         int       `json:"forks"`
	Contributors  int       `json:"contributors"`
	LastCommit    time.Time `json:"last_commit"`
	DefaultBranch string    `json:"default_branch"`
	HasCICD       bool      `json:"has_cicd"`
}

RepositoryInfo contains repository context information

type RiskAssessment

type RiskAssessment struct {
	// Core risk scores
	OverallRisk     float64 `json:"overall_risk"`
	ImpactScore     float64 `json:"impact_score"`
	LikelihoodScore float64 `json:"likelihood_score"`
	ExposureScore   float64 `json:"exposure_score"`

	// Risk level and category
	RiskLevel    RiskLevel    `json:"risk_level"`
	RiskCategory RiskCategory `json:"risk_category"`

	// Detailed breakdown
	ImpactFactors     ImpactFactors     `json:"impact_factors"`
	LikelihoodFactors LikelihoodFactors `json:"likelihood_factors"`
	ExposureFactors   ExposureFactors   `json:"exposure_factors"`

	// Mitigation recommendations
	Mitigations     []Mitigation    `json:"mitigations"`
	ComplianceFlags ComplianceFlags `json:"compliance_flags"`

	// Metadata
	AssessedAt   time.Time `json:"assessed_at"`
	AssessmentID string    `json:"assessment_id"`
}

RiskAssessment represents a comprehensive risk assessment result

type RiskAssessmentInput

type RiskAssessmentInput struct {
	// Finding details
	Finding         detection.Finding `json:"finding"`
	ConfidenceScore float64           `json:"confidence_score"`

	// Context information
	RepositoryInfo   RepositoryInfo   `json:"repository_info"`
	FileContext      FileContext      `json:"file_context"`
	OrganizationInfo OrganizationInfo `json:"organization_info"`

	// Additional context
	CoOccurrences  []detection.Finding `json:"co_occurrences"`
	HistoricalData HistoricalData      `json:"historical_data"`
}

RiskAssessmentInput contains all input data for risk assessment

type RiskCategory

type RiskCategory string

RiskCategory represents the category of risk

const (
	RiskCategoryIdentityTheft      RiskCategory = "IDENTITY_THEFT"
	RiskCategoryFinancialFraud     RiskCategory = "FINANCIAL_FRAUD"
	RiskCategoryPrivacyBreach      RiskCategory = "PRIVACY_BREACH"
	RiskCategoryRegulatoryBreach   RiskCategory = "REGULATORY_BREACH"
	RiskCategoryReputationalDamage RiskCategory = "REPUTATIONAL_DAMAGE"
	RiskCategoryOperational        RiskCategory = "OPERATIONAL"
)

type RiskLevel

type RiskLevel string

RiskLevel represents the risk severity following Australian banking guidelines

const (
	RiskLevelCritical RiskLevel = "CRITICAL" // 0.9+ - Immediate action required
	RiskLevelHigh     RiskLevel = "HIGH"     // 0.7-0.89 - Urgent attention needed
	RiskLevelMedium   RiskLevel = "MEDIUM"   // 0.4-0.69 - Review required
	RiskLevelLow      RiskLevel = "LOW"      // 0.0-0.39 - Monitor
)

type RiskMatrix

type RiskMatrix struct {
	// contains filtered or unexported fields
}

RiskMatrix provides a multi-dimensional risk assessment framework aligned with Australian banking and privacy regulations

func NewRiskMatrix

func NewRiskMatrix(config *RiskMatrixConfig) (*RiskMatrix, error)

NewRiskMatrix creates a new risk matrix calculator

func (*RiskMatrix) AssessRisk

func (rm *RiskMatrix) AssessRisk(input RiskAssessmentInput) (*RiskAssessment, error)

AssessRisk performs a comprehensive risk assessment

type RiskMatrixConfig

type RiskMatrixConfig struct {
	// Risk calculation method
	UseMultiplicativeModel bool    `json:"use_multiplicative_model"`
	ImpactWeight           float64 `json:"impact_weight"`
	LikelihoodWeight       float64 `json:"likelihood_weight"`
	ExposureWeight         float64 `json:"exposure_weight"`

	// Australian regulatory alignments
	APRAAligned       bool `json:"apra_aligned"`
	PrivacyActAligned bool `json:"privacy_act_aligned"`

	// Risk thresholds
	CriticalThreshold float64 `json:"critical_threshold"` // 0.8+
	HighThreshold     float64 `json:"high_threshold"`     // 0.6-0.79
	MediumThreshold   float64 `json:"medium_threshold"`   // 0.4-0.59
	LowThreshold      float64 `json:"low_threshold"`      // 0.2-0.39

	// Context modifiers
	ProductionMultiplier float64 `json:"production_multiplier"`
	PublicRepoMultiplier float64 `json:"public_repo_multiplier"`
	SensitivePathBonus   float64 `json:"sensitive_path_bonus"`
}

RiskMatrixConfig holds configuration for risk matrix calculations

func DefaultRiskMatrixConfig

func DefaultRiskMatrixConfig() *RiskMatrixConfig

DefaultRiskMatrixConfig returns the default risk matrix configuration

type ScoreAdjustment

type ScoreAdjustment struct {
	Type        string  `json:"type"`
	Impact      float64 `json:"impact"`
	Description string  `json:"description"`
}

ScoreAdjustment represents modifications to the base score

type ScoreAggregator

type ScoreAggregator struct {
	// contains filtered or unexported fields
}

ScoreAggregator combines individual factor scores into a final confidence score and provides detailed breakdowns for audit and regulatory compliance

func NewScoreAggregator

func NewScoreAggregator(config *AggregatorConfig) (*ScoreAggregator, error)

NewScoreAggregator creates a new score aggregator

func (*ScoreAggregator) AggregateScores

func (a *ScoreAggregator) AggregateScores(factors FactorScores) float64

AggregateScores combines all factor scores into a final confidence score

func (*ScoreAggregator) GenerateAuditTrail

func (a *ScoreAggregator) GenerateAuditTrail(factors FactorScores, finalScore float64, piType detection.PIType) []AuditEntry

GenerateAuditTrail creates a comprehensive audit trail for regulatory compliance

func (*ScoreAggregator) GenerateRegulatoryCompliance

func (a *ScoreAggregator) GenerateRegulatoryCompliance(piType detection.PIType, riskLevel RiskLevel) RegulatoryCompliance

GenerateRegulatoryCompliance creates regulatory compliance information

func (*ScoreAggregator) GenerateScoreBreakdown

func (a *ScoreAggregator) GenerateScoreBreakdown(factors FactorScores, finalScore float64) ScoreBreakdown

GenerateScoreBreakdown creates a detailed breakdown of how the score was calculated

func (*ScoreAggregator) MapScoreToRiskLevel

func (a *ScoreAggregator) MapScoreToRiskLevel(score float64) RiskLevel

MapScoreToRiskLevel maps a confidence score to a risk level

type ScoreBreakdown

type ScoreBreakdown struct {
	FinalScore  float64            `json:"final_score"`
	Components  []ScoreComponent   `json:"components"`
	Weights     map[string]float64 `json:"weights"`
	Adjustments []ScoreAdjustment  `json:"adjustments"`
}

ScoreBreakdown provides detailed information about how the score was calculated

type ScoreComponent

type ScoreComponent struct {
	Name        string  `json:"name"`
	Score       float64 `json:"score"`
	Weight      float64 `json:"weight"`
	Description string  `json:"description"`
}

ScoreComponent represents an individual scoring component

type ScoreInput

type ScoreInput struct {
	// Core finding data
	Finding detection.Finding `json:"finding"`
	Content string            `json:"content"`

	// Component scores
	ProximityScore  *ProximityScore  `json:"proximity_score,omitempty"`
	MLScore         *MLScore         `json:"ml_score,omitempty"`
	ValidationScore *ValidationScore `json:"validation_score,omitempty"`

	// Context data
	CoOccurrences []CoOccurrence `json:"co_occurrences,omitempty"`
	Environment   string         `json:"environment,omitempty"`

	// Metadata
	ScanTimestamp time.Time `json:"scan_timestamp"`
}

ScoreInput contains all the input data needed for confidence scoring

type ValidationScore

type ValidationScore struct {
	IsValid    bool    `json:"is_valid"`
	Algorithm  string  `json:"algorithm"`
	Confidence float64 `json:"confidence"`
	Details    string  `json:"details,omitempty"`
}

ValidationScore represents algorithmic validation results

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL