| package bundle |
|
|
| |
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| type BundleSignals struct { |
| DelegatesToBundledScript bool `json:"delegates_to_bundled_script"` |
| ShipsOpaqueExecutable bool `json:"ships_opaque_executable"` |
| CompiledWithoutMatchingSource bool `json:"compiled_without_matching_source"` |
| CompiledSourceMismatch bool `json:"compiled_source_mismatch"` |
| ArchiveContainsExecutable bool `json:"archive_contains_executable"` |
| ReferencesUnscannedFiletype bool `json:"references_unscanned_filetype"` |
| DelegatesToData bool `json:"delegates_to_data"` |
| DelegatesToImage bool `json:"delegates_to_image"` |
| NLDirectiveActiveTools bool `json:"nl_directive_active_tools"` |
| SymlinkedExecutableReference bool `json:"symlinked_executable_reference"` |
| PaddingEvasion bool `json:"padding_evasion"` |
| HiddenPayloadFiles int `json:"hidden_payload_files"` |
| PayloadToMarkdownRatio float64 `json:"payload_to_markdown_ratio"` |
| MaxSiblingAnalyzerRisk float64 `json:"max_sibling_analyzer_risk"` |
| CorroboratedHighRisk bool `json:"corroborated_high_risk"` |
| } |
|
|
| |
| |
| |
| |
| |
| var signalAliases = map[string][]string{ |
| "DelegatesToBundledScript": {"delegates-to-bundled-script"}, |
| "ShipsOpaqueExecutable": {"ships-opaque-executable"}, |
| "CompiledWithoutMatchingSource": {"compiled-without-matching-source", "ships-compiled-bytecode"}, |
| "CompiledSourceMismatch": {"compiled-source-mismatch"}, |
| "ArchiveContainsExecutable": {"archive-contains-executable"}, |
| "ReferencesUnscannedFiletype": {"references-unscanned-filetype"}, |
| "DelegatesToData": {"delegates-to-data"}, |
| "DelegatesToImage": {"delegates-to-image"}, |
| "NLDirectiveActiveTools": {"allowed-tools-nl-directive", "nl-directive-active-tools", "nl-directive"}, |
| "SymlinkedExecutableReference": {"symlinked-executable-reference"}, |
| "PaddingEvasion": {"padding-evasion"}, |
| } |
|
|
| |
| |
| func AggregateSignals(b *Bundle, findings []Finding) BundleSignals { |
| var s BundleSignals |
|
|
| present := make(map[string]bool, len(findings)) |
| for _, f := range findings { |
| present[f.Signal] = true |
| if w := severityToWeight(f.Severity); w > s.MaxSiblingAnalyzerRisk { |
| s.MaxSiblingAnalyzerRisk = w |
| } |
| |
| |
| if severityToWeight(f.Severity) >= severityToWeight(SevHigh) && |
| (f.Corroborated || !f.Structural) { |
| s.CorroboratedHighRisk = true |
| } |
| } |
|
|
| s.DelegatesToBundledScript = anyPresent(present, signalAliases["DelegatesToBundledScript"]) |
| s.ShipsOpaqueExecutable = anyPresent(present, signalAliases["ShipsOpaqueExecutable"]) |
| s.CompiledWithoutMatchingSource = anyPresent(present, signalAliases["CompiledWithoutMatchingSource"]) |
| s.CompiledSourceMismatch = anyPresent(present, signalAliases["CompiledSourceMismatch"]) |
| s.ArchiveContainsExecutable = anyPresent(present, signalAliases["ArchiveContainsExecutable"]) |
| s.ReferencesUnscannedFiletype = anyPresent(present, signalAliases["ReferencesUnscannedFiletype"]) |
| s.DelegatesToData = anyPresent(present, signalAliases["DelegatesToData"]) |
| s.DelegatesToImage = anyPresent(present, signalAliases["DelegatesToImage"]) |
| s.NLDirectiveActiveTools = anyPresent(present, signalAliases["NLDirectiveActiveTools"]) |
| s.SymlinkedExecutableReference = anyPresent(present, signalAliases["SymlinkedExecutableReference"]) |
| s.PaddingEvasion = anyPresent(present, signalAliases["PaddingEvasion"]) |
|
|
| s.HiddenPayloadFiles = countHiddenPayloadFiles(b, findings) |
| s.PayloadToMarkdownRatio = payloadToMarkdownRatio(b) |
|
|
| return s |
| } |
|
|
| |
| func anyPresent(present map[string]bool, names []string) bool { |
| for _, n := range names { |
| if present[n] { |
| return true |
| } |
| } |
| return false |
| } |
|
|
| |
| |
| |
| func countHiddenPayloadFiles(b *Bundle, findings []Finding) int { |
| if b == nil { |
| return 0 |
| } |
| withFinding := make(map[string]bool, len(findings)) |
| for _, f := range findings { |
| if f.File != "" { |
| withFinding[f.File] = true |
| } |
| } |
| n := 0 |
| for _, f := range b.Files { |
| if f == nil || !f.Hidden { |
| continue |
| } |
| if f.Kind == KindMarkdown || f.Kind == KindSkillMd { |
| continue |
| } |
| if withFinding[f.RelPath] { |
| n++ |
| } |
| } |
| return n |
| } |
|
|
| |
| |
| func payloadToMarkdownRatio(b *Bundle) float64 { |
| if b == nil { |
| return 0 |
| } |
| md := b.SkillMdBytes |
| if md < 1 { |
| md = 1 |
| } |
| return float64(b.PayloadBytes) / float64(md) |
| } |
|
|
| |
| |
| func (s BundleSignals) Names() []string { |
| return []string{ |
| "delegates_to_bundled_script", |
| "ships_opaque_executable", |
| "compiled_without_matching_source", |
| "compiled_source_mismatch", |
| "archive_contains_executable", |
| "references_unscanned_filetype", |
| "delegates_to_data", |
| "delegates_to_image", |
| "nl_directive_active_tools", |
| "symlinked_executable_reference", |
| "padding_evasion", |
| "hidden_payload_files", |
| "payload_to_markdown_ratio", |
| "max_sibling_analyzer_risk", |
| "corroborated_high_risk", |
| } |
| } |
|
|
| |
| |
| |
| func (s BundleSignals) ToSlice() []float64 { |
| return []float64{ |
| b2f(s.DelegatesToBundledScript), |
| b2f(s.ShipsOpaqueExecutable), |
| b2f(s.CompiledWithoutMatchingSource), |
| b2f(s.CompiledSourceMismatch), |
| b2f(s.ArchiveContainsExecutable), |
| b2f(s.ReferencesUnscannedFiletype), |
| b2f(s.DelegatesToData), |
| b2f(s.DelegatesToImage), |
| b2f(s.NLDirectiveActiveTools), |
| b2f(s.SymlinkedExecutableReference), |
| b2f(s.PaddingEvasion), |
| float64(s.HiddenPayloadFiles), |
| s.PayloadToMarkdownRatio, |
| s.MaxSiblingAnalyzerRisk, |
| b2f(s.CorroboratedHighRisk), |
| } |
| } |
|
|
| func b2f(v bool) float64 { |
| if v { |
| return 1 |
| } |
| return 0 |
| } |
|
|