Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malicious code scanner #296

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from

Conversation

barv-jfrog
Copy link
Contributor

@barv-jfrog barv-jfrog commented Jan 29, 2025

  • The pull request is targeting the dev branch.
  • The code has been validated to compile successfully by running go vet ./....
  • The code has been formatted properly using go fmt ./....
  • All static analysis checks passed.
  • All tests have passed. If this feature is not already covered by the tests, new tests have been added.
  • Updated the Contributing page / ReadMe page / CI Workflow files if needed.
  • All changes are detailed at the description. if not already covered at JFrog Documentation, new documentation have been added.

depends on:


Description:

New malicious scanners which check for malicious code on the source code. For example, models such as pickle may contain malicious code in their code, so now jf audit can scan this pickles and show in a table what is the malicious code.


Example:

image

Copy link
Contributor

@attiasas attiasas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Improve PR details, Link related PRs
  2. Please add tests! there are multiple places to add them
  3. Take a look at my comments.
  4. Make sure the PM are aware of the output and approve the text and UI before merge

Comment on lines 25 to 26
MaliciousVulnerabilities []SourceCodeRow `json:"malicious_code"`
MaliciousViolations []SourceCodeRow `json:"maliciousViolations"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MaliciousVulnerabilities []SourceCodeRow `json:"malicious_code"`
MaliciousViolations []SourceCodeRow `json:"maliciousViolations"`
MaliciousVulnerabilities []SourceCodeRow `json:"maliciousCode"`
MaliciousViolations []SourceCodeRow `json:"maliciousViolations"`

make sure the formats are the same...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines 164 to 170
if sjc.current == nil {
return results.ErrResetConvertor
}
maliciousSimpleJson, err := PrepareSimpleJsonJasIssues(sjc.entitledForJas, sjc.pretty, results.ScanResultsToRuns(maliciousFindings)...)
if err != nil || len(maliciousSimpleJson) == 0 {
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if sjc.current == nil {
return results.ErrResetConvertor
}
maliciousSimpleJson, err := PrepareSimpleJsonJasIssues(sjc.entitledForJas, sjc.pretty, results.ScanResultsToRuns(maliciousFindings)...)
if err != nil || len(maliciousSimpleJson) == 0 {
return
}
if sjc.current == nil {
return results.ErrResetConvertor
}
for i := range maliciousFindings {
if shouldUpdateStatus(sjc.current.Statuses.MaliciousStatusCode, &maliciousFindings[i].StatusCode) {
sjc.current.Statuses.MaliciousStatusCode = &maliciousFindings[i].StatusCode
}
}
maliciousSimpleJson, err := PrepareSimpleJsonJasIssues(sjc.entitledForJas, sjc.pretty, results.ScanResultsToRuns(maliciousFindings)...)
if err != nil || len(maliciousSimpleJson) == 0 {
return
}

Add this scan to the status attributes so we can use it in all other places to display the command information

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

go.mod Outdated
@@ -114,7 +114,7 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
)

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20250126110945-81abbdde452f
replace github.com/jfrog/jfrog-client-go => ../jfrog-client-go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for remote push, while developing, make sure you are pointing to a valid branch.
This is expceting the code to be in the machine locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if generalError = addJasScanTaskForModuleIfNeeded(params, utils.ContextualAnalysisScan, runContextualScan(params.Runner, params.Scanner, params.ScanResults, params.Module, params.DirectDependencies, params.ThirdPartyApplicabilityScan, params.ApplicableScanType, params.TargetOutputDir)); generalError != nil {
return
}
//if generalError = addJasScanTaskForModuleIfNeeded(params, utils.ContextualAnalysisScan, runContextualScan(params.Runner, params.Scanner, params.ScanResults, params.Module, params.DirectDependencies, params.ThirdPartyApplicabilityScan, params.ApplicableScanType, params.TargetOutputDir)); generalError != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to uncomment when done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@barv-jfrog barv-jfrog added the safe to test Approve running integration tests on a pull request label Mar 2, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Mar 2, 2025
@attiasas attiasas self-requested a review March 4, 2025 07:32
Copy link
Contributor

@attiasas attiasas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, take a look at my comments, in addition:

  1. fix failed tests
  2. add description to the PR details, make sure to explain the type of scan and add screen shots so the users can understand and reference to.
  3. Add integration tests at audit_test.go that runs and validate a malicious issues on a project

{
"tool": {
"driver": {
"name": "JFrog Terraform scanner",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"name": "JFrog Terraform scanner",
"name": "JFrog Malicious Code scanner",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -102,6 +108,8 @@ func addJasScanTaskForModuleIfNeeded(params JasRunnerParams, subScan utils.SubSc
enabled = params.ConfigProfile.Modules[0].ScanConfig.IacScannerConfig.EnableIacScan
case jasutils.Applicability:
enabled = params.ConfigProfile.Modules[0].ScanConfig.EnableContextualAnalysisScan
case jasutils.MaliciousCode:
enabled = params.ConfigProfile.Modules[0].ScanConfig.MaliciousScannerConfig.EnableMaliciousScan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we also added this to the config at the platform?

@barv-jfrog barv-jfrog added the safe to test Approve running integration tests on a pull request label Mar 4, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Mar 4, 2025
@barv-jfrog barv-jfrog added the safe to test Approve running integration tests on a pull request label Mar 4, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Mar 4, 2025
@barv-jfrog barv-jfrog added the safe to test Approve running integration tests on a pull request label Mar 4, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Mar 4, 2025
@barv-jfrog barv-jfrog added the safe to test Approve running integration tests on a pull request label Mar 4, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Mar 4, 2025
@barv-jfrog barv-jfrog added the safe to test Approve running integration tests on a pull request label Mar 4, 2025
@github-actions github-actions bot removed the safe to test Approve running integration tests on a pull request label Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants