Skip to content

Commit

Permalink
chore: remove dynamic severity entirely (#1504)
Browse files Browse the repository at this point in the history
* chore: remove dynamic severity entirely

* fix: update snapshots
  • Loading branch information
cfabianski committed Feb 21, 2024
1 parent b3942b4 commit c43608e
Show file tree
Hide file tree
Showing 29 changed files with 41 additions and 163 deletions.
2 changes: 1 addition & 1 deletion e2e/.snapshots/TestCache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
critical:
high:
- rule:
cwe_ids:
- "42"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{"source":"Bearer","version":"dev","findings":[{"cwe_ids":["42"],"id":"test_ruby_logger","title":"Ruby logger","description":"Ruby logger","documentation_url":"","line_number":1,"full_filename":"e2e/flags/testdata/simple/main.rb","filename":"main.rb","data_type":{"category_uuid":"cef587dd-76db-430b-9e18-7b031e1a193b","name":"Email Address"},"category_groups":["PII","Personal Data"],"source":{"start":1,"end":1,"column":{"start":26,"end":36}},"sink":{"start":1,"end":1,"column":{"start":1,"end":37},"content":"logger.info(\"user info\", user.email)"},"parent_line_number":1,"snippet":"logger.info(\"user info\", user.email)","fingerprint":"fa5e03644738e4c17cbbd04a580506b1_0","old_fingerprint":"8240e1537878783bac845d1163c80555_0","code_extract":"logger.info(\"user info\", user.email)","severity":"critical"}]}
{"source":"Bearer","version":"dev","findings":[{"cwe_ids":["42"],"id":"test_ruby_logger","title":"Ruby logger","description":"Ruby logger","documentation_url":"","line_number":1,"full_filename":"e2e/flags/testdata/simple/main.rb","filename":"main.rb","data_type":{"category_uuid":"cef587dd-76db-430b-9e18-7b031e1a193b","name":"Email Address"},"category_groups":["PII","Personal Data"],"source":{"start":1,"end":1,"column":{"start":26,"end":36}},"sink":{"start":1,"end":1,"column":{"start":1,"end":37},"content":"logger.info(\"user info\", user.email)"},"parent_line_number":1,"snippet":"logger.info(\"user info\", user.email)","fingerprint":"fa5e03644738e4c17cbbd04a580506b1_0","old_fingerprint":"8240e1537878783bac845d1163c80555_0","code_extract":"logger.info(\"user info\", user.email)","severity":"high"}]}

--
Analyzing codebase
Expand Down
2 changes: 1 addition & 1 deletion e2e/rules/.snapshots/TestAuxilary-testdata-data-auxilary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids:
- "201"
Expand Down
2 changes: 1 addition & 1 deletion e2e/rules/.snapshots/TestSanitizer-testdata-data-sanitizer
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
critical:
high:
- rule:
cwe_ids:
- "42"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: rule_logger_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: rule_logger_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: java_rule_logger_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: java_rule_logger_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: javascript_test_datatype_rule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: javascript_test_datatype_rule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: javascript_insecure_url_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: javascript_insecure_url_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: javascript_insecure_url_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: javascript_insecure_url_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: javascript_insecure_url_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: php_rule_logger_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: php_rule_logger_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: rule_logger_test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: rule_logger_test
Expand Down
2 changes: 1 addition & 1 deletion internal/languages/ruby/.snapshots/TestRuby--call.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: logger_test_rule
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
high:
low:
- rule:
cwe_ids: []
id: logger_test_rule
Expand Down
4 changes: 2 additions & 2 deletions internal/report/output/privacy/.snapshots/TestAddReportData
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
DataType: (string) (len=13) "Email Address",
DetectionCount: (int) 1,
CriticalRiskFindingCount: (int) 0,
HighRiskFindingCount: (int) 1,
HighRiskFindingCount: (int) 0,
MediumRiskFindingCount: (int) 0,
LowRiskFindingCount: (int) 0,
RulesPassedCount: (int) 0
Expand All @@ -29,7 +29,7 @@
(string) (len=13) "Email Address"
},
CriticalRiskFindingCount: (int) 0,
HighRiskFindingCount: (int) 1,
HighRiskFindingCount: (int) 0,
MediumRiskFindingCount: (int) 0,
LowRiskFindingCount: (int) 0,
RulesPassedCount: (int) 0
Expand Down
4 changes: 2 additions & 2 deletions internal/report/output/privacy/.snapshots/TestBuildCsvString
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

Subject,Data Types,Detection Count,Critical Risk Finding,High Risk Finding,Medium Risk Finding,Low Risk Finding,Rules Passed
User,Email Address,1,0,1,0,0,0
User,Email Address,1,0,0,0,0,0
Unknown,Country,1,0,0,0,0,1

Third Party,Subject,Data Types,Critical Risk Finding,High Risk Finding,Medium Risk Finding,Low Risk Finding,Rules Passed
Sentry,User,"Email Address",0,1,0,0,0
Sentry,User,"Email Address",0,0,0,0,0

16 changes: 6 additions & 10 deletions internal/report/output/security/.snapshots/TestAddReportData
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@
RawCodeExtract: ([]file.Line) {
},
SeverityMeta: (types.SeverityMeta) {
RuleSeverity: (string) (len=3) "low",
SensitiveDataCategories: ([]string) (len=3) {
(string) (len=3) "PII",
(string) (len=13) "Personal Data",
(string) (len=25) "Personal Data (Sensitive)"
},
HasLocalDataTypes: (*bool)(true),
SensitiveDataCategoryWeighting: (int) 3,
RuleSeverityWeighting: (int) 2,
FinalWeighting: (int) 8,
RuleSeverity: (string) (len=8) "critical",
SensitiveDataCategories: ([]string) <nil>,
HasLocalDataTypes: (*bool)(<nil>),
SensitiveDataCategoryWeighting: (int) 0,
RuleSeverityWeighting: (int) 0,
FinalWeighting: (int) 0,
DisplaySeverity: (string) (len=8) "critical"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@
RawCodeExtract: ([]file.Line) {
},
SeverityMeta: (types.SeverityMeta) {
RuleSeverity: (string) (len=3) "low",
SensitiveDataCategories: ([]string) (len=3) {
(string) (len=3) "PII",
(string) (len=13) "Personal Data",
(string) (len=25) "Personal Data (Sensitive)"
},
HasLocalDataTypes: (*bool)(true),
SensitiveDataCategoryWeighting: (int) 3,
RuleSeverityWeighting: (int) 2,
FinalWeighting: (int) 8,
RuleSeverity: (string) (len=8) "critical",
SensitiveDataCategories: ([]string) <nil>,
HasLocalDataTypes: (*bool)(<nil>),
SensitiveDataCategoryWeighting: (int) 0,
RuleSeverityWeighting: (int) 0,
FinalWeighting: (int) 0,
DisplaySeverity: (string) (len=8) "critical"
}
}
Expand Down
50 changes: 0 additions & 50 deletions internal/report/output/security/.snapshots/TestCalculateSeverity

This file was deleted.

55 changes: 2 additions & 53 deletions internal/report/output/security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,60 +472,9 @@ func CalculateSeverity(groups []string, severity string, hasLocalDataTypes bool)
}
}

if !hasLocalDataTypes {
return types.SeverityMeta{
RuleSeverity: severity,
DisplaySeverity: severity,
}
}

// highest sensitive data category
sensitiveDataCategoryWeighting := 0
if slices.Contains(groups, "PHI") {
sensitiveDataCategoryWeighting = 3
} else if slices.Contains(groups, "Personal Data (Sensitive)") {
sensitiveDataCategoryWeighting = 3
} else if slices.Contains(groups, "Personal Data") {
sensitiveDataCategoryWeighting = 2
} else if slices.Contains(groups, "PII") {
sensitiveDataCategoryWeighting = 1
}

var ruleSeverityWeighting int
switch severity {
case globaltypes.LevelCritical:
ruleSeverityWeighting = 8
case globaltypes.LevelHigh:
ruleSeverityWeighting = 5
case globaltypes.LevelMedium:
ruleSeverityWeighting = 3
default:
ruleSeverityWeighting = 2 // low weighting as default
}

triggerWeighting := 2

var displaySeverity string
finalWeighting := ruleSeverityWeighting + (sensitiveDataCategoryWeighting * triggerWeighting)
switch {
case finalWeighting >= 8:
displaySeverity = globaltypes.LevelCritical
case finalWeighting >= 5:
displaySeverity = globaltypes.LevelHigh
case finalWeighting >= 3:
displaySeverity = globaltypes.LevelMedium
default:
displaySeverity = globaltypes.LevelLow
}

return types.SeverityMeta{
RuleSeverity: severity,
SensitiveDataCategories: groups,
HasLocalDataTypes: &hasLocalDataTypes,
RuleSeverityWeighting: ruleSeverityWeighting,
SensitiveDataCategoryWeighting: sensitiveDataCategoryWeighting,
FinalWeighting: finalWeighting,
DisplaySeverity: displaySeverity,
RuleSeverity: severity,
DisplaySeverity: severity,
}
}

Expand Down
13 changes: 0 additions & 13 deletions internal/report/output/security/security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

dataflowtypes "github.com/bearer/bearer/internal/report/output/dataflow/types"
"github.com/bearer/bearer/internal/report/output/security"
securitytypes "github.com/bearer/bearer/internal/report/output/security/types"
"github.com/bearer/bearer/internal/report/output/testhelper"
outputtypes "github.com/bearer/bearer/internal/report/output/types"
)
Expand Down Expand Up @@ -201,18 +200,6 @@ func TestAddReportDataWithFailOnSeverity(t *testing.T) {
}
}

func TestCalculateSeverity(t *testing.T) {
res := []securitytypes.SeverityMeta{
security.CalculateSeverity([]string{"PHI", "Personal Data"}, "low", true),
security.CalculateSeverity([]string{"Personal Data (Sensitive)"}, "low", false),
security.CalculateSeverity([]string{"Personal Data"}, "low", false),
security.CalculateSeverity([]string{"Personal Data"}, "warning", false),
security.CalculateSeverity([]string{}, "warning", false),
}

cupaloy.SnapshotT(t, res)
}

func TestFingerprintIsStableWithBaseBranchFindings(t *testing.T) {
config, err := generateConfig(flagtypes.ReportOptions{Report: "security"})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/report/output/testhelper/testhelper.go

Large diffs are not rendered by default.

0 comments on commit c43608e

Please sign in to comment.