-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/fixing downstream kiro vulnerability scans #19
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
Open
AntonBarashSnyk
wants to merge
4
commits into
main
Choose a base branch
from
feat/updating-kiro-vulnerability-scan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d90221d
feat: Adding transitive dependency vulnerability checking so downstre…
AntonBarashSnyk 4f23eef
feat: Adding transitive dependency vulnerability checking so downstre…
AntonBarashSnyk 2cb0240
fix: updated files to use new methods and delete old vuln and severit…
AntonBarashSnyk 7940ee2
fix: changing package comparison to compare using == instead of in fo…
AntonBarashSnyk 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 |
|---|---|---|
|
|
@@ -417,18 +417,19 @@ def get_sca_with_cache( | |
| print_cache_status(True, f"{pkg_name}@{version}") | ||
|
|
||
| # Convert cached vulns back to DependencyVulnerability objects | ||
| # The cache now includes the full dependency tree | ||
| for v in cached.vulnerabilities: | ||
| all_vulns.append(DependencyVulnerability( | ||
| id=v.get("id", "unknown"), | ||
| title=v.get("title", "Unknown"), | ||
| severity=v.get("severity", "medium"), | ||
| package_name=pkg_name, | ||
| installed_version=version, | ||
| package_name=v.get("package_name", pkg_name), | ||
| installed_version=v.get("installed_version", version), | ||
| fixed_version=v.get("fixed_version"), | ||
| cve=v.get("cve"), | ||
| cvss_score=None, | ||
| is_direct=True, | ||
| dependency_path=[] | ||
| is_direct=v.get("package_name") == pkg_name, | ||
| dependency_path=v.get("dependency_path", []) | ||
| )) | ||
| else: | ||
| cache_misses += 1 | ||
|
|
@@ -448,23 +449,49 @@ def get_sca_with_cache( | |
| if v.id not in cached_ids: | ||
| all_vulns.append(v) | ||
|
|
||
| # Cache results per package | ||
| packages_cached: Dict[str, List[Dict]] = {} | ||
| # Cache results per TOP-LEVEL package with their full dependency trees | ||
| # Group vulnerabilities by the first package in the dependency path (the top-level package) | ||
| packages_cached: Dict[str, Dict] = {} | ||
|
|
||
| for v in fresh_result.vulnerabilities: | ||
| key = f"{v.package_name}@{v.installed_version}" | ||
| if key not in packages_cached: | ||
| packages_cached[key] = [] | ||
| packages_cached[key].append({ | ||
| "id": v.id, | ||
| "title": v.title, | ||
| "severity": v.severity, | ||
| "fixed_version": v.fixed_version, | ||
| "cve": v.cve | ||
| }) | ||
| # Find the top-level package (first package after project name in dependency path) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non blocknig. The pre-commit is getting kinda big. Maybe we should move this chunk into one of the existing files or make a new file for it |
||
| if len(v.dependency_path) >= 2: | ||
| # dependency_path looks like: ['snyk-test-repo@1.0.0', 'express@4.14.1', ...] | ||
| top_level = v.dependency_path[1] # e.g., 'express@4.14.1' | ||
|
|
||
| # Extract package name and version | ||
| if '@' in top_level: | ||
| parts = top_level.rsplit('@', 1) | ||
| if len(parts) == 2: | ||
| top_pkg_name, top_pkg_version = parts | ||
| key = f"{top_pkg_name}@{top_pkg_version}" | ||
|
|
||
| if key not in packages_cached: | ||
| packages_cached[key] = { | ||
| "package": top_pkg_name, | ||
| "version": top_pkg_version, | ||
| "vulnerabilities": [] | ||
| } | ||
|
|
||
| packages_cached[key]["vulnerabilities"].append({ | ||
| "id": v.id, | ||
| "title": v.title, | ||
| "severity": v.severity, | ||
| "fixed_version": v.fixed_version, | ||
| "cve": v.cve, | ||
| "package_name": v.package_name, | ||
| "installed_version": v.installed_version, | ||
| "dependency_path": v.dependency_path | ||
| }) | ||
|
|
||
| # Cache each top-level package with its full tree | ||
| if DEBUG: | ||
| print(f"Caching {len(packages_cached)} top-level packages") | ||
| for key in packages_cached: | ||
| print(f" {key}: {len(packages_cached[key]['vulnerabilities'])} vulnerabilities") | ||
|
|
||
| for key, vulns in packages_cached.items(): | ||
| pkg, ver = key.rsplit("@", 1) | ||
| cache.set_sca_result(pkg, ver, vulns) | ||
| for key, data in packages_cached.items(): | ||
| cache.set_sca_result(data["package"], data["version"], data["vulnerabilities"]) | ||
| else: | ||
| print_warning(f"SCA scan failed: {fresh_result.error_message}") | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious: where is SNYK_HOOK_LOG_DIR set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not set anywhere explicitly right now, so presumably this line will always set LOG_DIR to /tmp unless there is an environment variable set for SNYK_HOOK_LOG_DIR by the user. I think having this as the default is fine since it'll fallback to tmp