Skip to content

Commit

Permalink
token validation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
barv-jfrog committed Sep 12, 2024
1 parent 0e5823c commit 94fdb71
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
10 changes: 8 additions & 2 deletions formats/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,19 @@ func ConvertToOperationalRiskViolationScanTableRow(rows []OperationalRiskViolati

func ConvertToSecretsTableRow(rows []SourceCodeRow) (tableRows []secretsTableRow) {
for i := range rows {
var status string
var info string
if rows[i].Applicability != nil {
status = rows[i].Applicability.Status
info = rows[i].Applicability.ScannerDescription
}
tableRows = append(tableRows, secretsTableRow{
severity: rows[i].Severity,
file: rows[i].File,
lineColumn: strconv.Itoa(rows[i].StartLine) + ":" + strconv.Itoa(rows[i].StartColumn),
secret: rows[i].Snippet,
tokenValidation: jasutils.TokenValidationStatus(rows[i].Applicability.Status).ToString(),
tokenInfo: jasutils.TokenValidationStatus(rows[i].Applicability.ScannerDescription).String(),
tokenValidation: jasutils.TokenValidationStatus(status).ToString(),
tokenInfo: info,
})

}
Expand Down
8 changes: 0 additions & 8 deletions formats/sarifutils/sarifutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ func GetResultProperty(key string, result *sarif.Result) string {
return ""
}

func GetResultPropertyTokenValidation(result *sarif.Result) string {
return GetResultProperty("tokenValidation", result)
}

func GetResultPropertyMetadata(result *sarif.Result) string {
return GetResultProperty("metadata", result)
}

func GetLocationRelatedCodeFlowsFromResult(location *sarif.Location, result *sarif.Result) (codeFlows []*sarif.CodeFlow) {
for _, codeFlow := range result.CodeFlows {
for _, stackTrace := range codeFlow.ThreadFlows {
Expand Down
20 changes: 16 additions & 4 deletions utils/resultstable.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ func prepareSecrets(secrets []*sarif.Run, isTable bool) []formats.SourceCodeRow
}
for _, location := range secretResult.Locations {
var applicability *formats.Applicability
status := sarifutils.GetResultPropertyTokenValidation(secretResult)
statusDescription := sarifutils.GetResultPropertyMetadata(secretResult)
status := GetResultPropertyTokenValidation(secretResult)
statusDescription := GetResultPropertyMetadata(secretResult)
if status != "" || statusDescription != "" {
applicability = &formats.Applicability{Status: status,
ScannerDescription: statusDescription}
Expand Down Expand Up @@ -392,12 +392,16 @@ func prepareSecrets(secrets []*sarif.Run, isTable bool) []formats.SourceCodeRow
return secretsRows
}

func PrintSecretsTable(secrets []*sarif.Run, entitledForSecretsScan bool) error {
func PrintSecretsTable(secrets []*sarif.Run, entitledForSecretsScan bool, tokenValidationEnabled bool) error {
if entitledForSecretsScan {
secretsRows := prepareSecrets(secrets, true)
log.Output()
return coreutils.PrintTable(formats.ConvertToSecretsTableRow(secretsRows), "Secret Detection",
err := coreutils.PrintTable(formats.ConvertToSecretsTableRow(secretsRows), "Secret Detection",
"✨ No secrets were found ✨", false)
if err == nil && entitledForSecretsScan && tokenValidationEnabled {
log.Output("This table contains multiple secret types, such as tokens, generic password, ssh keys and more, token validation is only supported on tokens.")
}
return err
}
return nil
}
Expand Down Expand Up @@ -1047,6 +1051,14 @@ func GetRuleUndeterminedReason(rule *sarif.ReportingDescriptor) string {
return sarifutils.GetRuleProperty("undetermined_reason", rule)
}

func GetResultPropertyTokenValidation(result *sarif.Result) string {
return sarifutils.GetResultProperty("tokenValidation", result)
}

func GetResultPropertyMetadata(result *sarif.Result) string {
return sarifutils.GetResultProperty("metadata", result)
}

func getApplicabilityStatusFromRule(rule *sarif.ReportingDescriptor) jasutils.ApplicabilityStatus {
if rule.Properties["applicability"] != nil {
status, ok := rule.Properties["applicability"].(string)
Expand Down
9 changes: 3 additions & 6 deletions utils/resultwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,9 @@ func (rw *ResultsWriter) printScanResultsTables() (err error) {
}
}
if shouldPrintTable(rw.subScansPreformed, SecretsScan, rw.results.ResultType) {
if err = PrintSecretsTable(rw.results.ExtendedScanResults.SecretsScanResults, rw.results.ExtendedScanResults.EntitledForJas); err != nil {
if err = PrintSecretsTable(rw.results.ExtendedScanResults.SecretsScanResults, rw.results.ExtendedScanResults.EntitledForJas, rw.results.ExtendedScanResults.SecretValidation); err != nil {
return
}
if rw.results.ExtendedScanResults.SecretValidation && rw.results.ExtendedScanResults.EntitledForJas {
log.Output("This table contains multiple secret types, such as tokens, generic password, ssh keys and more, token validation is only supported on tokens.")
}
}
if shouldPrintTable(rw.subScansPreformed, IacScan, rw.results.ResultType) {
if err = PrintIacTable(rw.results.ExtendedScanResults.IacScanResults, rw.results.ExtendedScanResults.EntitledForJas); err != nil {
Expand Down Expand Up @@ -791,10 +788,10 @@ func getBinaryLocationMarkdownString(commandType CommandType, subScanType SubSca
if snippet := sarifutils.GetLocationSnippet(location); snippet != "" {
content += fmt.Sprintf("\nEvidence: %s", snippet)
}
if tokenValidation := sarifutils.GetResultPropertyTokenValidation(result); tokenValidation != "" {
if tokenValidation := GetResultPropertyTokenValidation(result); tokenValidation != "" {
content += fmt.Sprintf("\nToken Validation %s", tokenValidation)
}
if metadata := sarifutils.GetResultPropertyMetadata(result); metadata != "" {
if metadata := GetResultPropertyMetadata(result); metadata != "" {
content += fmt.Sprintf("\nMetadata %s", metadata)
}
return
Expand Down

0 comments on commit 94fdb71

Please sign in to comment.