-
Notifications
You must be signed in to change notification settings - Fork 28
Add OSS-Realtime scan functionality to identify malicious packages (AST-95475, AST-95476, AST-95478) #1131
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
Merged
Merged
Add OSS-Realtime scan functionality to identify malicious packages (AST-95475, AST-95476, AST-95478) #1131
Changes from 11 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
fb25cc7
Add OSS-Realtime scan functionality to identify malicious packages
cx-ben-alvo 5754b3d
Refactor oss-realtime to use dynamic file source flag
cx-ben-alvo a586e1b
Integrate OSS Realtime Scanner with caching support
cx-ben-alvo 6a7731e
Add realtimeScannerWrapper to integration test setup
cx-ben-alvo 58bb681
Refactor OSS Realtime command structure and add comments
cx-ben-alvo e120514
Add requirements.txt and package.json with tests for OSS scanning
cx-ben-alvo d18b58e
Enhance RealtimeScannerMockWrapper to generate dynamic mock responses…
cx-ben-alvo dc140e8
Refactor cache file path computation into a helper function.
cx-ben-alvo da6c926
Refactor OSS Realtime scan functions and enhance cache managementRefa…
cx-ben-alvo 62106f7
Refactor OSS cache test logic and update function usage.
cx-ben-alvo 8788d8e
Rename test function for OSS Realtime scan to improve clarity
cx-ben-alvo bed6fd2
Update scanning functionality to support multiple files input
cx-ben-alvo 2b07bbe
Update test file paths in OSS Realtime scan tests for consistency
cx-ben-alvo f4c0350
Fix error message in ReadCache() test to dereference got value for cl…
cx-ben-alvo f84bccf
Add additional dependencies for manifest parser in golangci configura…
cx-ben-alvo a1a193b
Update manifest parser dependencies in golangci configuration
cx-ben-alvo ce02872
Update CI configuration for Go setup and linting
cx-ben-alvo bc086a4
Update golangci-lint version to v2.1.6 in CI configuration
cx-ben-alvo 5e6fb74
Update golangci-lint action to a specific commit for consistency
cx-ben-alvo 3747ac9
Update golangci-lint configuration to version 2 and refine linter set…
cx-ben-alvo b98a30f
Remove typecheck from golangci-lint configuration
cx-ben-alvo b8c3a13
Refactor golangci-lint configuration by removing deprecated settings …
cx-ben-alvo df3cf65
Enhance golangci-lint configuration with new linters and refined sett…
cx-ben-alvo 15f2869
Add 'go mod tidy' step to CI workflow for dependency management
cx-ben-alvo c80bf1d
Remove typecheck linter from golangci-lint configuration
cx-ben-alvo 40e9b4b
Add typecheck linter and update golangci-lint version to 1.64.2
cx-ben-alvo 276812b
Add typecheck linter and update golangci-lint version to 1.64.2
cx-ben-alvo c2d9d1d
fix linter errors
cx-ben-alvo c2ce243
fix linter errors
cx-ben-alvo 10afbf1
Update file path in tests to correct relative directory
cx-ben-alvo 03e2008
Update file path in tests to reflect new directory structure
cx-ben-alvo 4a8dc62
Update file paths in tests to match new directory structure
cx-ben-alvo d0d9881
Replace reflect.DeepEqual with assert.Equal in cache tests
cx-ben-alvo 8fa3fc5
Update file path in tests to correct relative directory
cx-ben-alvo fdc64e6
Update assertion in cache test to use asserts.True for TTL comparison
cx-ben-alvo baf4900
Merge branch 'main' into feature/benalvo/oss-realtime
cx-ben-alvo 1707e60
Refactor OSS realtime scanning API and remove license check.
cx-ben-alvo 3399946
Update CustomScan function to accept OssPackageRequest instead of slice
cx-ben-alvo cdcca32
Fix linter
cx-ben-alvo b071351
Refactor prepareScan and scanAndCache functions to use pointers for r…
cx-ben-alvo f369ed4
Add integration tests and dependencies for OSS Realtime scans
cx-ben-alvo a7605ff
Refactor deleteCacheFile function to remove unnecessary parameter
cx-ben-alvo 01759c5
Remove error logging for non-existent cache file in validation function
cx-ben-alvo 7546341
Update .golangci.yml to refine linting configuration
cx-ben-alvo 727aea9
Remove shadow check from golangci.yml linting configuration
cx-ben-alvo 0caabe6
Remove revive linter from golangci.yml configuration
cx-ben-alvo 4744700
Update .golangci.yml to replace maligned with revive linter
cx-ben-alvo 8add563
Add nil check for JwtWrapper in ensureLicense function
cx-ben-alvo ea2a130
Skip test for invalid license due to unimplemented license check and …
cx-ben-alvo 1fc5b4b
Fix assertion to check length of Packages in toScan
cx-ben-alvo e293de7
Merge branch 'main' into feature/benalvo/oss-realtime
cx-ben-alvo 5bf17ca
Refactor OSSRealtime logic into a dedicated service
cx-ben-alvo 8cfa716
Remove unused RealtimeScannerWrapperParams struct from oss-realtime.go
cx-ben-alvo 1afdf6c
Add error handling for missing file path in RunOssRealtimeScan
cx-ben-alvo c6c4b27
Add revive rule to golangci configuration to disable stuttering check
cx-ben-alvo 2d2e13a
Add feature flag for OSS Realtime and update manifest-parser import path
cx-ben-alvo 97de44b
Enable OSS Realtime feature flag in test cases
cx-ben-alvo 90bfea6
Refactor OSS Realtime scanning to use new data structures and improve…
cx-ben-alvo 6b77bc9
Refactor OSS Realtime service methods to remove receiver and improve …
cx-ben-alvo f9bb7ce
Move OssPackage and OssPackageResults types to config.go for better o…
cx-ben-alvo e76f535
Refactor OSS Realtime scanning to create package map after preparing …
cx-ben-alvo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "dependencies": { | ||
| "@CheckmarxDev/ast-cli-javascript-wrapper": "file:../ast-cli-javascript-wrapper/CheckmarxDev-ast-cli-javascript-wrapper-0.0.54.tgz", | ||
| "@checkmarxdev/ast-cli-javascript-wrapper": "0.0.54", | ||
| "copyfiles": "200", | ||
| "tree-kill": "^1.2.2" | ||
| }, | ||
| "description": "Beat vulnerabilities with more-secure code", | ||
| "devDependencies": { | ||
| "@types/chai": "4.3.1", | ||
| "@types/mocha": "9.1.1", | ||
| "@types/node": "^18.0.0", | ||
| "@types/vscode": "^1.50.0", | ||
| "@typescript-eslint/eslint-plugin": "^5.29.0", | ||
| "@typescript-eslint/parser": "^5.29.0", | ||
| "chai": "4.3.6", | ||
| "eslint": "^8.18.0", | ||
| "mocha": "10.0.0", | ||
| "typescript": "^4.7.4", | ||
| "vsce": "^2.9.2", | ||
| "vscode-extension-tester": "4.2.5", | ||
| "vscode-extension-tester-locators": "^1.62.2", | ||
| "webpack": "^5.73.0", | ||
| "webpack-cli": "^4.10.0" | ||
| }, | ||
| "version": "2.0.4" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # | ||
| # This file is autogenerated by pip-compile with Python 3.10 | ||
| # by the following command: | ||
| # | ||
| # pip-compile | ||
| # | ||
| contourpy==1.3.1 | ||
| # via matplotlib | ||
| c==0.12.1 | ||
| # via matplotlib | ||
| fonttools==4.55.8 | ||
| # via matplotlib | ||
| kiwisolver==1.4.8 | ||
| # via matplotlib | ||
| matplotlib==3.10.0 | ||
| # via | ||
| # -r requirements.in | ||
| # seaborn | ||
| numpy==2.2.2 | ||
| # viaS | ||
| # -r requirements.in | ||
| # contourpy | ||
| # matplotlib | ||
| # pandas | ||
| # seaborn | ||
| packaging==24.2 | ||
| # via matplotlib | ||
| pandas==2.2.3 | ||
| # via | ||
| # -r requirements.in | ||
| # seaborn | ||
| pillow==11.1.0 | ||
| # via matplotlib | ||
| pyparsing==3.2.1 | ||
| # via matplotlib | ||
| python-dateutil==2.9.0.post0 | ||
| # via | ||
| # matplotlib | ||
| # pandas | ||
| pytz==2025.1 | ||
| # via pandas | ||
| seaborn==0.13.2 | ||
| # via -r requirements.in | ||
| six==1.17.0 | ||
| # via python-dateutil | ||
| tzdata==2025.1 | ||
| # via pandas | ||
|
|
||
|
|
||
| # Sample requirements.txt with various package specifiers | ||
|
|
||
| # Exact version | ||
|
|
||
| flask==1.1.2 | ||
|
|
||
| # Range: greater than or equal and less than | ||
|
|
||
| Django>=3.0,<4.0 | ||
|
|
||
| # Less than or equal | ||
|
|
||
| requests<=2.25.1 | ||
|
|
||
| # Compatible release (PEP 440) | ||
|
|
||
| urllib3\~=1.26.0 | ||
|
|
||
| # Not equal | ||
|
|
||
| numpy!=1.19.0 | ||
|
|
||
| # Wildcard patch version | ||
|
|
||
| pandas==1.2.\* | ||
|
|
||
| # Extras | ||
|
|
||
| package\_with\_extras\[security,docs]==0.1.0 | ||
|
|
||
| # Environment marker (skip on Python>=3.8) | ||
|
|
||
| scipy==1.5.2; python\_version < "3.8" | ||
|
|
||
| # Combined ranges with comma | ||
|
|
||
| celery>=4.0,<5.0 | ||
|
|
||
| # Inline comment | ||
|
|
||
| gevent==21.8.0 # pinned to a known-good version | ||
|
|
||
| # Full-line comment below should be ignored | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/checkmarx/ast-cli/internal/commands/util/printer" | ||
| commonParams "github.com/checkmarx/ast-cli/internal/params" | ||
| "github.com/checkmarx/ast-cli/internal/services/ossrealtime" | ||
| "github.com/checkmarx/ast-cli/internal/wrappers" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func RunScanOssRealtimeCommand(realtimeScannerWrapper wrappers.RealtimeScannerWrapper, jwtWrapper wrappers.JWTWrapper, featureFlagWrapper wrappers.FeatureFlagsWrapper) func(cmd *cobra.Command, args []string) error { | ||
| return func(cmd *cobra.Command, args []string) error { | ||
| fileSourceFlag, _ := cmd.Flags().GetString(commonParams.SourcesFlag) | ||
| if fileSourceFlag == "" { | ||
| return errors.New("file source flag is required") | ||
| } | ||
| wrapperParams := ossrealtime.RealtimeScannerWrapperParams{ | ||
| RealtimeScannerWrapper: realtimeScannerWrapper, | ||
| JwtWrapper: jwtWrapper, | ||
| FeatureFlagWrapper: featureFlagWrapper, | ||
| } | ||
|
|
||
| packages, err := ossrealtime.RunOssRealtimeScan(&wrapperParams, fileSourceFlag) | ||
| if err != nil { | ||
| return errors.New("failed to run oss-realtime scan: " + err.Error()) | ||
| } | ||
| err = printer.Print(cmd.OutOrStdout(), packages, printer.FormatJSON) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package commands | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestRunScanOssRealtimeCommand_RequirementsTxtFile_ScanSuccess(t *testing.T) { | ||
| execCmdNilAssertion( | ||
| t, | ||
| "scan", "oss-realtime", "-s", "data/manifests/requirements.txt", | ||
| ) | ||
| } | ||
|
|
||
| func TestRunScanOssRealtimeCommand_EmptyFilePath_ScanFailed(t *testing.T) { | ||
| err := execCmdNotNilAssertion( | ||
| t, | ||
| "scan", "oss-realtime", "-s", "", | ||
| ) | ||
| assert.NotNil(t, err) | ||
| } | ||
|
|
||
| func TestRunScanOssRealtimeCommand_PackageJsonFile_ScanSuccess(t *testing.T) { | ||
| execCmdNilAssertion( | ||
| t, | ||
| "scan", "oss-realtime", "-s", "data/manifests/package.json", | ||
| ) | ||
| } | ||
| func TestRunScanOssRealtimeCommand_UnsupportedFileType_ScanFailed(t *testing.T) { | ||
| err := execCmdNotNilAssertion( | ||
| t, | ||
| "scan", "oss-realtime", "-s", "not-supported-extension.txt", | ||
| ) | ||
| assert.NotNil(t, err) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.