-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Wizcli improvements #12446
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
OsamaMahmood
wants to merge
31
commits into
DefectDojo:bugfix
Choose a base branch
from
OsamaMahmood:wizcli-improvements
base: bugfix
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
Wizcli improvements #12446
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
aeda530
severity mapping
OsamaMahmood 0f6830e
extract reference link if present in scan output
OsamaMahmood d019619
improved parsing and implimented generation of unique id for deduplic…
OsamaMahmood f89d858
improved scan result parsers for dir, iac, img scan results
OsamaMahmood 30ec0e2
improvements
OsamaMahmood f8dcca7
enabling dedup in settings.dist.py
OsamaMahmood 2673b5a
Merge branch 'bugfix' into wizcli-improvements
OsamaMahmood 58c5687
Merge branch 'DefectDojo:master' into wizcli-improvements
OsamaMahmood f7e40d3
updated unit test files
OsamaMahmood b135abf
updated unit test to reflect latest cahnges in the parser
OsamaMahmood 974715f
switched dedp algo to HASH_CODE for wizcli
OsamaMahmood b5ea466
fixed ruff
OsamaMahmood dfb95f6
fixed unitests
OsamaMahmood 8576a5f
fixed ruff
OsamaMahmood 59fa30d
Fixed unit test and ruff issues
OsamaMahmood 395fff4
fix to assertions
OsamaMahmood d78b537
fixed remaining assertions
OsamaMahmood 6a21f00
fixes
OsamaMahmood a804dcc
updates
OsamaMahmood ae1cd2a
fixed img test
OsamaMahmood 3d42de8
Update versions in application files
37d8af6
Merge pull request #12571 from DefectDojo/release/2.47.1
rossops c41158d
Merge branch 'DefectDojo:master' into wizcli-improvements
OsamaMahmood 7ed4298
added HASHCODE_FIELDS_PER_SCANNER entries for these parser
OsamaMahmood f9c7365
removed unique id generation and use
OsamaMahmood 16812ad
fixed ruff errors
OsamaMahmood 8dd415e
updated hashcode logic for wizcli scans
OsamaMahmood 1253ef1
type in wizcli iac parser name
OsamaMahmood 8fcb8de
added relase notes
OsamaMahmood 40ad1dd
rephrased to make it clrear to understand
OsamaMahmood 715d098
added fallback value if fixedVersion not found
OsamaMahmood 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,36 +1,66 @@ | ||
import json | ||
import logging | ||
|
||
from dojo.tools.wizcli_common_parsers.parsers import WizcliParsers | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class WizcliDirParser: | ||
|
||
"""Wizcli Dir Scan results in JSON file format.""" | ||
"""Wiz CLI Directory/IaC Scan results in JSON file format.""" | ||
|
||
def get_scan_types(self): | ||
return ["Wizcli Dir Scan"] | ||
|
||
def get_label_for_scan_types(self, scan_type): | ||
return "Wizcli Dir Scan" | ||
return "Wiz CLI Scan (Directory)" | ||
|
||
def get_description_for_scan_types(self, scan_type): | ||
return "Wizcli Dir Scan results in JSON file format." | ||
return "Parses Wiz CLI Directory/IaC scan results in JSON format, creating granular findings for vulnerabilities and secrets." | ||
|
||
def get_findings(self, filename, test): | ||
scan_data = filename.read() | ||
def get_findings(self, file, test): | ||
"""Processes the JSON report and returns a list of DefectDojo Finding objects.""" | ||
try: | ||
data = json.loads(scan_data.decode("utf-8")) | ||
except Exception: | ||
scan_data = file.read() | ||
if isinstance(scan_data, bytes): | ||
# Try decoding common encodings | ||
try: | ||
scan_data = scan_data.decode("utf-8-sig") # Handles BOM | ||
except UnicodeDecodeError: | ||
scan_data = scan_data.decode("utf-8") # Fallback | ||
data = json.loads(scan_data) | ||
except json.JSONDecodeError as e: | ||
msg = f"Invalid JSON format: {e}" | ||
logger.error(msg) | ||
raise ValueError(msg) from e | ||
except Exception as e: | ||
msg = f"Error processing report file: {e}" | ||
logger.error(msg) | ||
raise ValueError(msg) from e | ||
|
||
findings = [] | ||
results = data.get("result", {}) | ||
results_data = data.get("result", {}) | ||
|
||
if not results_data: | ||
logger.warning("No 'result' key found in the Wiz report. Unable to parse findings.") | ||
return findings | ||
|
||
libraries = results.get("libraries", None) | ||
# Parse Libraries (Vulnerabilities) | ||
libraries = results_data.get("libraries") | ||
if libraries: | ||
logger.debug(f"Parsing {len(libraries)} library entries.") | ||
findings.extend(WizcliParsers.parse_libraries(libraries, test)) | ||
else: | ||
logger.debug("No 'libraries' data found in results.") | ||
|
||
secrets = results.get("secrets", None) | ||
# Parse Secrets | ||
secrets = results_data.get("secrets") | ||
if secrets: | ||
logger.debug(f"Parsing {len(secrets)} secret entries.") | ||
findings.extend(WizcliParsers.parse_secrets(secrets, test)) | ||
else: | ||
logger.debug("No 'secrets' data found in results.") | ||
|
||
logger.info(f"WizcliDirParser processed {len(findings)} findings.") | ||
return findings |
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 |
---|---|---|
@@ -1,36 +1,64 @@ | ||
import json | ||
import logging | ||
|
||
from dojo.tools.wizcli_common_parsers.parsers import WizcliParsers | ||
from dojo.tools.wizcli_common_parsers.parsers import WizcliParsers # Adjust import path | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
class WizcliIaCParser: | ||
|
||
"""Wizcli IaC Scan results in JSON file format.""" | ||
class WizcliIacParser: | ||
|
||
"""Wiz CLI IaC Scan results in JSON file format.""" | ||
|
||
def get_scan_types(self): | ||
return ["Wizcli IaC Scan"] | ||
|
||
def get_label_for_scan_types(self, scan_type): | ||
return "Wizcli IaC Scan" | ||
return "Wiz CLI Scan (IaC)" | ||
|
||
def get_description_for_scan_types(self, scan_type): | ||
return "Wizcli IaC Scan results in JSON file format." | ||
return "Parses Wiz CLI Infrastructure as Code (IaC) scan results in JSON format." | ||
|
||
def get_findings(self, filename, test): | ||
scan_data = filename.read() | ||
def get_findings(self, file, test): | ||
try: | ||
data = json.loads(scan_data.decode("utf-8")) | ||
except Exception: | ||
scan_data = file.read() | ||
if isinstance(scan_data, bytes): | ||
try: | ||
scan_data = scan_data.decode("utf-8-sig") | ||
except UnicodeDecodeError: | ||
scan_data = scan_data.decode("utf-8") | ||
data = json.loads(scan_data) | ||
except json.JSONDecodeError as e: | ||
msg = f"Invalid JSON format: {e}" | ||
logger.error(msg) | ||
raise ValueError(msg) from e | ||
except Exception as e: | ||
msg = f"Error processing report file: {e}" | ||
logger.error(msg) | ||
raise ValueError(msg) from e | ||
|
||
findings = [] | ||
results = data.get("result", {}) | ||
results_data = data.get("result", {}) | ||
|
||
if not results_data: | ||
logger.warning("No 'result' key found in the Wiz report.") | ||
return findings | ||
|
||
rule_matches = results.get("ruleMatches", None) | ||
# Parse Rule Matches (IaC findings) | ||
rule_matches = results_data.get("ruleMatches") | ||
if rule_matches: | ||
logger.debug(f"Parsing {len(rule_matches)} rule match entries.") | ||
findings.extend(WizcliParsers.parse_rule_matches(rule_matches, test)) | ||
else: | ||
logger.debug("No 'ruleMatches' data found in results.") | ||
|
||
secrets = results.get("secrets", None) | ||
# Parse Secrets (if present in IaC scans) | ||
secrets = results_data.get("secrets") | ||
if secrets: | ||
logger.debug(f"Parsing {len(secrets)} secret entries.") | ||
findings.extend(WizcliParsers.parse_secrets(secrets, test)) | ||
else: | ||
logger.debug("No 'secrets' data found in results.") | ||
|
||
logger.info(f"WizcliIacParser processed {len(findings)} findings.") | ||
return findings |
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 |
---|---|---|
@@ -1,40 +1,73 @@ | ||
import json | ||
import logging | ||
|
||
from dojo.tools.wizcli_common_parsers.parsers import WizcliParsers | ||
from dojo.tools.wizcli_common_parsers.parsers import WizcliParsers # Adjust import path | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class WizcliImgParser: | ||
|
||
"""Wizcli Image Scan results in JSON file format.""" | ||
"""Wiz CLI Container Image Scan results in JSON file format.""" | ||
|
||
def get_scan_types(self): | ||
# Use a distinct name for image scans | ||
return ["Wizcli Img Scan"] | ||
|
||
def get_label_for_scan_types(self, scan_type): | ||
return "Wizcli Img Scan" | ||
return "Wiz CLI Scan (Image)" | ||
|
||
def get_description_for_scan_types(self, scan_type): | ||
return "Wizcli Img report file can be imported in JSON format." | ||
return "Parses Wiz CLI Container Image scan results in JSON format." | ||
|
||
def get_findings(self, filename, test): | ||
scan_data = filename.read() | ||
def get_findings(self, file, test): | ||
try: | ||
data = json.loads(scan_data.decode("utf-8")) | ||
except Exception: | ||
scan_data = file.read() | ||
if isinstance(scan_data, bytes): | ||
try: | ||
scan_data = scan_data.decode("utf-8-sig") | ||
except UnicodeDecodeError: | ||
scan_data = scan_data.decode("utf-8") | ||
data = json.loads(scan_data) | ||
except json.JSONDecodeError as e: | ||
msg = f"Invalid JSON format: {e}" | ||
logger.error(msg) | ||
raise ValueError(msg) from e | ||
except Exception as e: | ||
msg = f"Error processing report file: {e}" | ||
logger.error(msg) | ||
raise ValueError(msg) from e | ||
|
||
findings = [] | ||
results = data.get("result", {}) | ||
results_data = data.get("result", {}) | ||
|
||
if not results_data: | ||
logger.warning("No 'result' key found in the Wiz report.") | ||
return findings | ||
|
||
osPackages = results.get("osPackages", None) | ||
if osPackages: | ||
findings.extend(WizcliParsers.parse_os_packages(osPackages, test)) | ||
# Parse OS Packages - Key difference for image scans | ||
os_packages = results_data.get("osPackages") | ||
if os_packages: | ||
logger.debug(f"Parsing {len(os_packages)} OS package entries.") | ||
findings.extend(WizcliParsers.parse_os_packages(os_packages, test)) | ||
else: | ||
logger.debug("No 'osPackages' data found in results.") | ||
|
||
libraries = results.get("libraries", None) | ||
# Parse Libraries (if present in image scans) | ||
libraries = results_data.get("libraries") | ||
if libraries: | ||
logger.debug(f"Parsing {len(libraries)} library entries.") | ||
findings.extend(WizcliParsers.parse_libraries(libraries, test)) | ||
else: | ||
logger.debug("No 'libraries' data found in results.") | ||
|
||
secrets = results.get("secrets", None) | ||
# Parse Secrets (if present in image scans) | ||
secrets = results_data.get("secrets") | ||
if secrets: | ||
logger.debug(f"Parsing {len(secrets)} secret entries.") | ||
findings.extend(WizcliParsers.parse_secrets(secrets, test)) | ||
else: | ||
logger.debug("No 'secrets' data found in results.") | ||
|
||
logger.info(f"WizcliImgParser processed {len(findings)} findings.") | ||
return findings |
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.
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.