Skip to content

feat: add vulnerabilities into cdx output when using folder hashing command #133

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 2 commits into from
Jul 10, 2025

Conversation

matiasdaloia
Copy link
Contributor

@matiasdaloia matiasdaloia commented Jul 10, 2025

Summary by CodeRabbit

  • New Features

    • Vulnerability information is now included in the CycloneDX output for folder scans.
  • Chores

    • Updated version to 1.28.0.
    • Updated changelog with details for the new release.
  • Style

    • Improved debug log message for clarity when sending vulnerability data.

@matiasdaloia matiasdaloia self-assigned this Jul 10, 2025
@matiasdaloia matiasdaloia added the enhancement New feature or request label Jul 10, 2025
Copy link

coderabbitai bot commented Jul 10, 2025

Walkthrough

The changes introduce vulnerability data into the CycloneDX output generated by the folder-scan feature. This is achieved by adding a method to append vulnerabilities to the CycloneDX dictionary, updating the scanner presenter to include vulnerability retrieval and insertion, and documenting the update in the changelog. The version is incremented to 1.28.0.

Changes

File(s) Change Summary
CHANGELOG.md Added entry for version 1.28.0 noting CycloneDX output now includes vulnerabilities in folder-scan.
src/scanoss/init.py Updated __version__ from '1.27.1' to '1.28.0'.
src/scanoss/cyclonedx.py Added _normalize_vulnerability_id, _create_vulnerability_entry, and append_vulnerabilities methods to CycloneDx class for handling vulnerabilities.
src/scanoss/scanners/scanner_hfh.py Enhanced _format_cyclonedx_output to retrieve and append vulnerabilities to CycloneDX output.
src/scanoss/scanossgrpc.py Updated debug log message in get_vulnerabilities_json for clarity.

Sequence Diagram(s)

sequenceDiagram
    participant Presenter as ScannerHFHPresenter
    participant Client as Scanner Client
    participant CycloneDx as CycloneDx

    Presenter->>Client: get_vulnerabilities_json(request)
    Client-->>Presenter: vulnerabilities_data
    Presenter->>CycloneDx: append_vulnerabilities(cdx_dict, vulnerabilities_data, purl)
    CycloneDx-->>Presenter: updated_cdx_dict
    Presenter-->>Presenter: Return CycloneDX JSON with vulnerabilities
Loading

Suggested reviewers

  • eeisegn

Poem

A new scan hops in with glee,
Vulnerabilities now plain to see!
CycloneDX grows strong and wise,
With each new risk it will apprise.
Version bumped, the code’s anew—
A safer warren for me and you!
🐇🔍🛡️

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93b2475 and 41e1d16.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • src/scanoss/__init__.py (1 hunks)
  • src/scanoss/cyclonedx.py (1 hunks)
  • src/scanoss/scanners/scanner_hfh.py (2 hunks)
  • src/scanoss/scanossgrpc.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/scanoss/scanossgrpc.py (1)
src/scanoss/scanossbase.py (1)
  • print_debug (58-63)
src/scanoss/scanners/scanner_hfh.py (2)
src/scanoss/scanossgrpc.py (2)
  • get_dependencies (248-255)
  • get_vulnerabilities_json (314-342)
src/scanoss/cyclonedx.py (1)
  • append_vulnerabilities (290-357)
🪛 GitHub Actions: Lint
src/scanoss/cyclonedx.py

[error] 290-290: Ruff: Too many branches (14 > 12) in function 'append_vulnerabilities'. (PLR0912)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (6)
src/scanoss/__init__.py (1)

25-25: LGTM! Version bump is appropriate.

The version increment to 1.28.0 correctly reflects the addition of vulnerability data to CycloneDX output as a new feature.

CHANGELOG.md (1)

12-14: LGTM! Changelog entry is well-formatted.

The entry accurately documents the new vulnerability functionality and follows the established changelog format.

src/scanoss/scanossgrpc.py (1)

329-329: LGTM! Debug message correction is accurate.

The updated debug message correctly describes the vulnerability data being sent, fixing the misleading reference to "crypto data."

src/scanoss/scanners/scanner_hfh.py (3)

196-199: LGTM! Well-structured vulnerability request creation.

The vulnerability request structure correctly mirrors the dependency request pattern and uses the appropriate purl and version data from the best match component.


202-202: LGTM! Proper integration of vulnerability retrieval.

The call to get_vulnerabilities_json is correctly placed after dependency retrieval and follows the established error handling pattern.


213-215: LGTM! Conditional vulnerability appending is well-implemented.

The vulnerability data is properly appended to the CycloneDX output only when present, maintaining defensive programming practices and avoiding unnecessary processing.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/scanoss/cyclonedx.py (1)

321-369: Excellent implementation that resolves the complexity issue.

The method properly handles vulnerability deduplication, uses the helper methods effectively, and maintains clean separation of concerns. The implementation successfully addresses the complexity threshold violation mentioned in past reviews.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41e1d16 and ec19a2e.

📒 Files selected for processing (1)
  • src/scanoss/cyclonedx.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (1)
src/scanoss/cyclonedx.py (1)

290-302: Good refactoring that addresses the complexity issue.

The method correctly normalizes vulnerability IDs and CVEs from different field names, and handles CPE entries appropriately by preferring CVE values when available.

Comment on lines +304 to +319
def _create_vulnerability_entry(self, vuln_id: str, vuln: dict, vuln_cve: str, purl: str) -> dict:
"""
Create a new vulnerability entry for CycloneDX format.
"""
vuln_source = vuln.get('source', '').lower()
return {
'id': vuln_id,
'source': {
'name': 'NVD' if vuln_source == 'nvd' else 'GitHub Advisories',
'url': f'https://nvd.nist.gov/vuln/detail/{vuln_cve}'
if vuln_source == 'nvd'
else f'https://github.com/advisories/{vuln_id}'
},
'ratings': [{'severity': self._sev_lookup(vuln.get('severity', 'unknown').lower())}],
'affects': [{'ref': purl}]
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Potential URL malformation for NVD vulnerabilities.

The method creates proper vulnerability entries, but there's a potential issue with URL construction when vuln_source is 'nvd' but vuln_cve is empty, which would result in a malformed URL.

Consider adding validation to ensure proper URL construction:

def _create_vulnerability_entry(self, vuln_id: str, vuln: dict, vuln_cve: str, purl: str) -> dict:
    """
    Create a new vulnerability entry for CycloneDX format.
    """
    vuln_source = vuln.get('source', '').lower()
+   
+   # Construct URL based on source and available data
+   if vuln_source == 'nvd' and vuln_cve:
+       url = f'https://nvd.nist.gov/vuln/detail/{vuln_cve}'
+   elif vuln_source == 'nvd':
+       url = f'https://nvd.nist.gov/vuln/detail/{vuln_id}'
+   else:
+       url = f'https://github.com/advisories/{vuln_id}'
+   
    return {
        'id': vuln_id,
        'source': {
            'name': 'NVD' if vuln_source == 'nvd' else 'GitHub Advisories',
-           'url': f'https://nvd.nist.gov/vuln/detail/{vuln_cve}'
-                 if vuln_source == 'nvd'
-                 else f'https://github.com/advisories/{vuln_id}'
+           'url': url
        },
        'ratings': [{'severity': self._sev_lookup(vuln.get('severity', 'unknown').lower())}],
        'affects': [{'ref': purl}]
    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def _create_vulnerability_entry(self, vuln_id: str, vuln: dict, vuln_cve: str, purl: str) -> dict:
"""
Create a new vulnerability entry for CycloneDX format.
"""
vuln_source = vuln.get('source', '').lower()
return {
'id': vuln_id,
'source': {
'name': 'NVD' if vuln_source == 'nvd' else 'GitHub Advisories',
'url': f'https://nvd.nist.gov/vuln/detail/{vuln_cve}'
if vuln_source == 'nvd'
else f'https://github.com/advisories/{vuln_id}'
},
'ratings': [{'severity': self._sev_lookup(vuln.get('severity', 'unknown').lower())}],
'affects': [{'ref': purl}]
}
def _create_vulnerability_entry(self, vuln_id: str, vuln: dict, vuln_cve: str, purl: str) -> dict:
"""
Create a new vulnerability entry for CycloneDX format.
"""
vuln_source = vuln.get('source', '').lower()
# Construct URL based on source and available data
if vuln_source == 'nvd' and vuln_cve:
url = f'https://nvd.nist.gov/vuln/detail/{vuln_cve}'
elif vuln_source == 'nvd':
url = f'https://nvd.nist.gov/vuln/detail/{vuln_id}'
else:
url = f'https://github.com/advisories/{vuln_id}'
return {
'id': vuln_id,
'source': {
'name': 'NVD' if vuln_source == 'nvd' else 'GitHub Advisories',
'url': url
},
'ratings': [
{
'severity': self._sev_lookup(
vuln.get('severity', 'unknown').lower()
)
}
],
'affects': [{'ref': purl}]
}
🤖 Prompt for AI Agents
In src/scanoss/cyclonedx.py around lines 304 to 319, the URL for NVD
vulnerabilities is constructed using vuln_cve without checking if vuln_cve is
empty, which can lead to malformed URLs. Add validation to check if vuln_cve is
non-empty before including it in the URL; if vuln_cve is empty, avoid appending
it or provide a fallback URL to ensure the URL is always valid.

@matiasdaloia matiasdaloia merged commit 07d3691 into main Jul 10, 2025
4 checks passed
@matiasdaloia matiasdaloia deleted the feature/mdaloia/add-vulns-to-cdx-hfh-output branch July 10, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant