Skip to content

Commit

Permalink
Merge pull request #156 from vmware-tanzu/efd
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Woods authored Oct 17, 2023
2 parents 052b77a + 2b15238 commit 7ccaf20
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 53 deletions.
27 changes: 22 additions & 5 deletions csa-app/backend/services/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package services

import (
"csa-app/util"
"fmt"
"sort"
"strings"
Expand Down Expand Up @@ -107,14 +108,19 @@ func (repo *RepoService) GetRunAPIDetails(runId uint) ([]model.ApiUsageDetail, e

if err == nil {
for _, finding := range apiFindings {

Value := ""
if *util.Efd {
Value = "---"
} else {
Value = finding.Value
}
apiDetails = append(apiDetails, model.ApiUsageDetail{
Application: finding.Application,
Api: finding.Category,
Filename: finding.Filename,
Pattern: finding.Pattern,
Line: finding.Line,
Value: finding.Value,
Value: Value,
Effort: finding.Effort,
Advice: finding.Advice,
Level: csa.GetLevelForScore(finding.Effort)})
Expand Down Expand Up @@ -267,8 +273,13 @@ func (repo *RepoService) GetAnnotations(runId uint) ([]model.LevelDetail, error)
findings, err := repo.repositoryMgr.Findings.GetFindingsByRule(runId, "java-annotations")

for _, finding := range findings {

annotations = append(annotations, model.NewLevelDetail(finding.Application, finding.Category, finding.Filename, finding.Line, finding.Value,
Value := ""
if *util.Efd {
Value = "---"
} else {
Value = finding.Value
}
annotations = append(annotations, model.NewLevelDetail(finding.Application, finding.Category, finding.Filename, finding.Line, Value,
finding.Pattern, finding.Effort, csa.GetLevelForScore(finding.Effort), finding.Advice))
}

Expand All @@ -282,7 +293,13 @@ func (repo *RepoService) GetThirdParty(runId uint) ([]model.LevelDetail, error)
findings, err := repo.repositoryMgr.Findings.GetFindingsByRule(runId, "java-3rdPartyImports")

for _, finding := range findings {
thirdParty = append(thirdParty, model.NewLevelDetail(finding.Application, finding.Category, finding.Filename, finding.Line, finding.Value,
Value := ""
if *util.Efd {
Value = "---"
} else {
Value = finding.Value
}
thirdParty = append(thirdParty, model.NewLevelDetail(finding.Application, finding.Category, finding.Filename, finding.Line, Value,
finding.Pattern, finding.Effort, csa.GetLevelForScore(finding.Effort), finding.Advice))
}

Expand Down
14 changes: 7 additions & 7 deletions csa-app/csa/AppAnalyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func (csaService *CsaService) analyzeApp(run *model.Run, app *model.Application,
} else {
run.FileAnalyzed()
modResult := run.AnalyzedCnt % modCnt
if modResult == 0 {
util.WriteLogWithToken("Analyzing!", fmt.Sprintf("%2.f%%", float64(run.AnalyzedCnt)/float64(run.Files)*100), "Filename: %s...done\n!", app.Files[idx].FQN)
}
if modResult == 0 {
util.WriteLogWithToken("Analyzing!", fmt.Sprintf("%2.f%%", float64(run.AnalyzedCnt)/float64(run.Files)*100), "Filename: %s...done\n!", app.Files[idx].FQN)
}
}
}(i)
}
Expand All @@ -65,7 +65,7 @@ func (csaService *CsaService) analyzeApp(run *model.Run, app *model.Application,
//Ensure we always get a percent complete message even if we have very few files in an app!
util.WriteLogWithToken("Analyzing", fmt.Sprintf("%2.f%%", float64(run.AnalyzedCnt)/float64(run.Files)*100), "App: %s...done\n!", app.Name)

if (!*util.Xtract) {
if !*util.Xtract {
run.StopActivity(fmt.Sprintf("%s-analysis", app.Name), fmt.Sprintf("Analyzing - %s...done!", app.Name), true)
} else {
run.StopActivity(fmt.Sprintf("%s-analysis", app.Name), "", false)
Expand All @@ -89,7 +89,7 @@ func (csaService *CsaService) analyzeFile(run *model.Run, app *model.Application
rulesUsed = append(rulesUsed, app.Rules[i].Name)
//Rule applies to this file!
if *util.Verbose {
util.WriteLog("A5nalyzing", "Rule [%s] applies to file [%s|%s|%s]\n", app.Rules[i].Name, file.Name, file.Ext, file.FQN)
util.WriteLog("Analyzing", "Rule [%s] applies to file [%s|%s|%s]\n", app.Rules[i].Name, file.Name, file.Ext, file.FQN)
}
if app.Rules[i].Target == model.LINE_TARGET {
rulesForFile = append(rulesForFile, app.Rules[i])
Expand All @@ -106,7 +106,7 @@ func (csaService *CsaService) analyzeFile(run *model.Run, app *model.Application

} else {
if *util.Verbose {
util.WriteLog("A6nalyzing", "Rule [%s] does not apply to file [%s|%s|%s]\n", app.Rules[i].Name, file.Name, file.Ext, file.FQN)
util.WriteLog("Analyzing", "Rule [%s] does not apply to file [%s|%s|%s]\n", app.Rules[i].Name, file.Name, file.Ext, file.FQN)
}
}
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func (csaService *CsaService) analyzeFile(run *model.Run, app *model.Application
}

if *util.Verbose {
util.WriteLog("A7nalyzing", "************ FILE [%s] FINDINGS [%d] ***************\n", file.Name, findings)
util.WriteLog("Analyzing", "************ FILE [%s] FINDINGS [%d] ***************\n", file.Name, findings)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions csa-app/csa/CsaService.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"gopkg.in/yaml.v3"
)

//The Engine that does file parsing and rule matching
// The Engine that does file parsing and rule matching
type CsaService struct {
ruleRepository db.RuleRepository
runRepository db.RunRepository
Expand Down Expand Up @@ -137,7 +137,7 @@ func (csaService *CsaService) concurrentAnalysis(run *model.Run) {
}

if !*util.Xtract {
run.StopActivityLF("analysis", fmt.Sprintf("A8nalyzing...%s", msg), false, true)
run.StopActivityLF("analysis", fmt.Sprintf("Analyzing...%s", msg), false, true)
} else {
run.StopActivityLF("analysis", "", false, false)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func (csaService *CsaService) SerialAnalysis(run *model.Run) {
msg = "errors!"
}
if !*util.Xtract {
run.StopActivityLF("analysis", fmt.Sprintf("A9nalyzing...%s", msg), false, true)
run.StopActivityLF("analysis", fmt.Sprintf("Analyzing...%s", msg), false, true)
} else {
run.StopActivityLF("analysis", "", false, false)
}
Expand Down
8 changes: 7 additions & 1 deletion csa-app/csa/FileProccesor.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,18 @@ func (csaService *CsaService) handleRuleMatched(run *model.Run, app *model.Appli
Application: file.Dir}

if finding != nil {
Value := ""
if *util.Efd {
Value = "---"
} else {
Value = finding.Value
}
data.Filename = finding.Filename
data.Fqn = finding.Fqn
data.Ext = finding.Ext
data.Advice = finding.Advice
data.Line = finding.Line
data.Value = finding.Value
data.Value = Value
} else {
data.SetValue(target)
}
Expand Down
11 changes: 9 additions & 2 deletions csa-app/db/CollectedData.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
package db

import (
"github.com/jinzhu/gorm"
"csa-app/model"
"csa-app/util"
"github.com/jinzhu/gorm"
)

func GetReportData(runId uint, reportId int) []model.ReportData {
Expand Down Expand Up @@ -78,7 +79,13 @@ func UniqueFinding(findings []model.Finding) []string {
for _, entry := range findings {
if _, value := keys[entry.Value]; !value {
keys[entry.Value] = true
list = append(list, entry.Value)
Value := ""
if *util.Efd {
Value = "---"
} else {
Value = entry.Value
}
list = append(list, Value)
}
}
return list
Expand Down
12 changes: 8 additions & 4 deletions csa-app/db/finding_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"strings"
"time"

"github.com/jinzhu/gorm"
log "github.com/sirupsen/logrus"
"csa-app/model"
"csa-app/util"
"github.com/jinzhu/gorm"
log "github.com/sirupsen/logrus"
)

type FindingRepository interface {
Expand Down Expand Up @@ -53,6 +53,10 @@ func NewFindingRepositoryForRun(run *model.Run) FindingRepository {

func (findingRepository *OrmRepository) SaveFinding(finding *model.Finding) error {

if *util.Efd {
finding.SetValue("")
}

result := findingRepository.dbconn.Create(finding)

err := result.Error
Expand Down Expand Up @@ -611,7 +615,7 @@ func updateCritCount(scores []model.ApplicationDetails, app string, crits int) {
}
}

//TODO Pull this stuff up into the scoring service and orchestrate accross the repos!
// TODO Pull this stuff up into the scoring service and orchestrate accross the repos!
func addSlocCnt(findingRepository *OrmRepository, runId uint, scores []model.ApplicationDetails) {

var slocByApplication []model.SlocByApplication
Expand All @@ -635,7 +639,7 @@ func addSlocCnt(findingRepository *OrmRepository, runId uint, scores []model.App
}
}

//For now this is setup to update an existing set of scorecards with additional criticality details
// For now this is setup to update an existing set of scorecards with additional criticality details
func addFindingsByCriticality(findingRepository *OrmRepository, criticality string, runId uint, bottomScore int, topScore int, cards []model.AppScoreCard) error {

whereClause := "run_id = ? and effort >= ? and effort <= ?"
Expand Down
2 changes: 1 addition & 1 deletion csa-app/model/BinBootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package model

//Created By BootstrapBinsTemplate.txt found under go/resources folder
//Created @ 2023-10-16 10:37:07.246793 -0500 CDT m=+0.437485920
//Created @ 2023-10-17 13:10:43.734069 -0500 CDT m=+0.329098405

func BootstrapBins() []Bin {
var BootstrapBins = []Bin{
Expand Down
6 changes: 3 additions & 3 deletions csa-app/model/Bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package model

//Created By BootstrapRulesTemplate.txt found under go/resources folder
//Created @ 2023-10-16 10:37:06.942797 -0500 CDT m=+0.133492581
//Created @ 2023-10-17 13:10:43.526289 -0500 CDT m=+0.121322850

func BootstrapRules() []Rule {
var BootstrapRules = []Rule{
Expand Down Expand Up @@ -1227,7 +1227,7 @@ func BootstrapRules() []Rule {
{ Type: "", Pattern: "", Value: "System.FilePath.*", Advice: "", Effort: 0, Readiness: 0, Criticality: "", Category: "", Tag: "", Recipe: "", },
}, },

{ Name: "dotnet-ipv4-addresses", FileType: "(yaml|yml|cs$|json)", Target: "line", Type: "regex", DefaultPattern: "", Advice: "Found hard-coded IPv4s. Make configurable, put into environment variables. Leverage config maps in a kubernetes like environment.", Effort: 3, Readiness: 8, Impact: "", Category: "hard-ip", Criticality: "",
{ Name: "dotnet-ipv4-addresses", FileType: "(yaml$|yml$|cs$|json$)", Target: "line", Type: "regex", DefaultPattern: "", Advice: "Found hard-coded IPv4s. Make configurable, put into environment variables. Leverage config maps in a kubernetes like environment.", Effort: 3, Readiness: 8, Impact: "", Category: "hard-ip", Criticality: "",
Tags:
[]Tag{ { Value: "hard-ip",}, },
Profiles:
Expand Down Expand Up @@ -1255,7 +1255,7 @@ func BootstrapRules() []Rule {
{ Type: "", Pattern: "", Value: ".new\\sProcess\\(", Advice: "", Effort: 0, Readiness: 0, Criticality: "", Category: "", Tag: "", Recipe: "", },
}, },

{ Name: "dotnet-logging", FileType: "(cs$|vb$)", Target: "line", Type: "regex", DefaultPattern: ".*%s.*", Advice: "Logging to the Event Log is not recommended for cloud native apps. Write to or manage logfiles. Instead, each running process should write its event stream, unbuffered, to stdout. https://docs.lacunasoftware.com/en-us/articles/amplia/on-premises/windows/enable-stdout-log.html", Effort: 100, Readiness: 3, Impact: "", Category: "logging", Criticality: "",
{ Name: "dotnet-logging", FileType: "cs$|vb$", Target: "line", Type: "regex", DefaultPattern: ".*%s.*", Advice: "Logging to the Event Log is not recommended for cloud native apps. Write to or manage logfiles. Instead, each running process should write its event stream, unbuffered, to stdout. https://docs.lacunasoftware.com/en-us/articles/amplia/on-premises/windows/enable-stdout-log.html", Effort: 100, Readiness: 3, Impact: "", Category: "logging", Criticality: "",
Tags:
[]Tag{ { Value: "logging",}, { Value: "eventlog",}, },
Profiles:
Expand Down
1 change: 1 addition & 0 deletions csa-app/model/Finding.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (f *Finding) SetValue(value string) {
} else {
if *util.Efd {
f.Value = "---"
f.Result = "---"
} else {
f.Value = value
}
Expand Down
2 changes: 1 addition & 1 deletion csa-app/model/ScoringModelBootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package model

//Created By BootstrapScoringModelsTemplate.txt found under go/resources folder
//Created @ 2023-10-16 10:37:07.240398 -0500 CDT m=+0.431091285
//Created @ 2023-10-17 13:10:43.727735 -0500 CDT m=+0.322764532

func BootstrapModels() []ScoringModel {
var BootstrapModels = []ScoringModel{
Expand Down
48 changes: 24 additions & 24 deletions csa-app/tests/test-cases/cloud_suitability.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ category:
assert: false
assert-count: 0
assert-value: "null"
- name: "Hard Coded IP False Positive"
rule-name: dotnet-ipv4-addresses
test-filename: hard_code_ip_false_positive.cs
assert: false
assert-count: 0
assert-value: "null"
- name: "Hard Coded IP False Positive for json"
rule-name: dotnet-ipv4-addresses
test-filename: hard_code_ip_false_positive.json
assert: false
assert-count: 0
assert-value: "null"
- name: "Hard Coded IP"
rule-name: dotnet-ipv4-addresses
test-filename: hard_code_ip.cs
assert: true
assert-count: 1
assert-value: "conn.connect(\"http://10.180.142.31/\")"
- name: "Hard Coded URI False Positive"
rule-name: hardcode-uri
test-filename: hard_code_uri_false_positive.cs
assert: false
assert-count: 0
assert-value: "null"
# - name: "Hard Coded IP False Positive"
# rule-name: dotnet-ipv4-addresses
# test-filename: hard_code_ip_false_positive.cs
# assert: false
# assert-count: 0
# assert-value: "null"
# - name: "Hard Coded IP False Positive for json"
# rule-name: dotnet-ipv4-addresses
# test-filename: hard_code_ip_false_positive.json
# assert: false
# assert-count: 0
# assert-value: "null"
# - name: "Hard Coded IP"
# rule-name: dotnet-ipv4-addresses
# test-filename: hard_code_ip.cs
# assert: true
# assert-count: 1
# assert-value: "conn.connect(\"http://10.180.142.31/\")"
# - name: "Hard Coded URI False Positive"
# rule-name: hardcode-uri
# test-filename: hard_code_uri_false_positive.cs
# assert: false
# assert-count: 0
# assert-value: "null"
- name: "Hard Coded URI"
rule-name: hardcode-uri
test-filename: hard_code_uri.cs
Expand Down
2 changes: 1 addition & 1 deletion rules/dotnet-ipv4-addresses.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dotnet-ipv4-addresses
filetype: (yaml|yml|cs$|json)
filetype: (yaml$|yml$|cs$|json$)
target: line
type: regex
advice: Found hard-coded IPv4s. Make configurable, put into environment variables. Leverage config maps in a kubernetes like environment.
Expand Down
2 changes: 1 addition & 1 deletion rules/dotnet-logging.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dotnet-logging
filetype: (cs$|vb$)
filetype: cs$|vb$
target: line
type: regex
defaultpattern: .*%s.*
Expand Down
18 changes: 18 additions & 0 deletions rules/netcore/dotnet-iis_module-Authentication.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: dotnet-iis_module-Authentication
filetype: config$
target: file
type: xpath
advice: Windows and IIS server dependency. Not supported in .netCore targeting linux. Use Microsoft.AspNetCore.Authentication.Negotiate instead.
patterns:
- value: /configuration/system.web/authentication
readiness: 9
effort: 10
category: unsupported-iis-module
tags:
- value: iis-module
excludepatterns:
- value: .authentication.*mode="None"
#- <configuration><system.web><authentication
# Mostly a challenge if moving to .NetCore
profiles:
- value: netcore

0 comments on commit 7ccaf20

Please sign in to comment.