Skip to content

Commit e6fc6e5

Browse files
Filter low-value crypto mentions (logs, labels, errors, docstrings)
Add isLowValueContext() to detect algorithm mentions in contexts that aren't actual cryptographic operations: - Log/print statements (fmt.Print, console.log, logger.*) - String labels (auth_method, authenticated_via, key_type) - Error message strings (must be valid, invalid key, failed to) - Docstrings (""", ''', sign a message using, verify using) This reduces false positives by filtering mentions like: - fmt.Printf("Generated Ed25519 keys...") - c.Locals("auth_method", "ed25519") - "publicKey must be a valid Ed25519 public key" Remaining findings are real crypto usage (function signatures, actual crypto calls like GenerateKey, Sign, Verify). Reduces noise by additional 12% (198 -> 174 findings on test repo).
1 parent a91357c commit e6fc6e5

1 file changed

Lines changed: 73 additions & 7 deletions

File tree

pkg/scanner/scanner.go

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,9 @@ func (s *Scanner) shouldIncludeFinding(f types.Finding) bool {
716716
}
717717
}
718718

719-
// Skip findings in documentation strings within code files
720-
// These are just descriptions, not actual crypto usage
721-
if isDocumentationString(f.Context) {
719+
// Skip findings in low-value contexts (logs, labels, error messages, docstrings)
720+
// These mention algorithms but aren't actual cryptographic operations
721+
if isLowValueContext(f.Context) {
722722
return false
723723
}
724724

@@ -733,11 +733,78 @@ func (s *Scanner) shouldIncludeFinding(f types.Finding) bool {
733733
return true
734734
}
735735

736-
// isDocumentationString checks if a line appears to be documentation/description
737-
// rather than actual crypto usage
738-
func isDocumentationString(line string) bool {
736+
// isLowValueContext checks if a line contains algorithm mentions in contexts
737+
// that are not actual cryptographic operations (logs, labels, error messages, docstrings)
738+
func isLowValueContext(line string) bool {
739739
lineLower := strings.ToLower(line)
740740

741+
// Log/print statements - algorithm mentioned in output, not usage
742+
logPatterns := []string{
743+
"fmt.print", "fmt.sprint", "fmt.fprint",
744+
"log.", "logger.", "logging.",
745+
"console.log", "console.error", "console.warn",
746+
"print(", "println(",
747+
"debug(", "info(", "warn(", "error(",
748+
}
749+
for _, pattern := range logPatterns {
750+
if strings.Contains(lineLower, pattern) {
751+
return true
752+
}
753+
}
754+
755+
// String labels/metadata - algorithm name as a value, not usage
756+
// e.g., "auth_method": "ed25519", c.Locals("authenticated_via", "ed25519")
757+
labelPatterns := []string{
758+
"auth_method",
759+
"authenticated_via",
760+
"authentication_type",
761+
"signing_algorithm",
762+
"encryption_algorithm",
763+
"key_type",
764+
"algorithm_name",
765+
"crypto_type",
766+
`"type":`,
767+
`"method":`,
768+
}
769+
for _, pattern := range labelPatterns {
770+
if strings.Contains(lineLower, pattern) {
771+
return true
772+
}
773+
}
774+
775+
// Error message strings - validation messages mentioning algorithms
776+
// e.g., "publicKey must be a valid Ed25519 public key"
777+
errorPatterns := []string{
778+
"must be a valid",
779+
"invalid.*key",
780+
"failed to",
781+
"error:",
782+
"expected.*got",
783+
"cannot be empty",
784+
}
785+
for _, pattern := range errorPatterns {
786+
if strings.Contains(lineLower, pattern) {
787+
return true
788+
}
789+
}
790+
791+
// Docstrings - documentation inside code
792+
// e.g., """Sign a message using Ed25519""", // Sign using Ed25519
793+
docstringPatterns := []string{
794+
`"""`, // Python docstring
795+
"'''", // Python docstring
796+
"sign a message using",
797+
"verify a message using",
798+
"encrypt using",
799+
"decrypt using",
800+
"generated.*key",
801+
}
802+
for _, pattern := range docstringPatterns {
803+
if strings.Contains(lineLower, pattern) {
804+
return true
805+
}
806+
}
807+
741808
// Common documentation patterns
742809
docPatterns := []string{
743810
"description:",
@@ -763,7 +830,6 @@ func isDocumentationString(line string) bool {
763830
"attestation", // Security attestation descriptions
764831
"capabilities", // Capability descriptions
765832
}
766-
767833
for _, pattern := range docPatterns {
768834
if strings.Contains(lineLower, pattern) {
769835
return true

0 commit comments

Comments
 (0)