Skip to content

feat: add CPE field to Service struct for Nmap service detection#1609

Merged
ehsandeep merged 2 commits intoprojectdiscovery:devfrom
b0bleet:feat/add-service-cpe
Jan 22, 2026
Merged

feat: add CPE field to Service struct for Nmap service detection#1609
ehsandeep merged 2 commits intoprojectdiscovery:devfrom
b0bleet:feat/add-service-cpe

Conversation

@b0bleet
Copy link
Copy Markdown
Contributor

@b0bleet b0bleet commented Dec 27, 2025

Summary by CodeRabbit

Release Notes

  • New Features
    • Services discovered during network scans now include Common Platform Enumeration (CPE) identifiers when available from scan results. CPEs are automatically extracted and added to service metadata, improving platform identification, asset inventory accuracy, and classification of detected services and systems.

✏️ Tip: You can customize this high-level summary in your review settings.

Add CPEs field to port.Service struct to expose Common Platform
Enumeration data from Nmap service detection. This enables consumers
to access standardized vendor/product/version information parsed
from CPE strings.
@auto-assign auto-assign bot requested a review from dwisiswant0 December 27, 2025 10:40
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 27, 2025

Walkthrough

Added CPE support by introducing a CPEs []string field to the port Service struct and propagating CPE values from nmap scan results into the Service.CPEs field during conversion.

Changes

Cohort / File(s) Summary
Service struct update
pkg/port/port.go
Added exported field CPEs []string with JSON tag json:"cpes,omitempty" to Service.
Nmap → naabu propagation
pkg/runner/nmap.go
Populates Service.CPEs on converted ports by extracting nmapPort.Service.CPEs into the naabu port Service during conversion.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nudge through ports with nimble feet,
Gathering CPEs both rare and neat,
From nmap whispers they tumble down,
I line them up, no need to frown,
A tiny rabbit, scanning the town 🍃

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: adding a CPE field to the Service struct for Nmap service detection, which aligns with the code modifications across pkg/port/port.go and pkg/runner/nmap.go.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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: 0

🧹 Nitpick comments (1)
pkg/port/port.go (1)

35-52: LGTM! CPEs field addition follows existing patterns.

The new CPEs field is properly structured with appropriate JSON tags. The omitempty tag ensures the field is excluded from JSON output when empty, which is the right behavior for optional CPE data.

Optional: Consider adding a documentation comment

While consistent with the existing undocumented fields, adding a brief comment explaining CPEs would improve clarity for future maintainers:

+	// CPEs contains Common Platform Enumeration identifiers for the detected service
 	CPEs        []string `json:"cpes,omitempty"`
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e3349aa and 75df497.

📒 Files selected for processing (2)
  • pkg/port/port.go
  • pkg/runner/nmap.go
🧰 Additional context used
🧬 Code graph analysis (1)
pkg/runner/nmap.go (1)
pkg/port/port.go (1)
  • Service (35-52)
🔇 Additional comments (2)
pkg/runner/nmap.go (2)

291-291: CPEs field assignment looks correct.

The CPEs field is properly assigned with the converted CPE strings, and it's correctly positioned within the Service struct initialization alongside other service metadata fields.


269-274: The CPE conversion implementation is correct and well-optimized. The nmap library v3.0.6 supports the Service.CPEs field, and the nmap.CPE to string conversion pattern used here (line 273) is consistent with existing usage elsewhere in the codebase (line 171). The pre-allocation strategy is efficient and handles edge cases properly.

Co-authored-by: Nakul Bharti <knakul853@gmail.com>
@Mzack9999 Mzack9999 requested a review from knakul853 January 21, 2026 12:15
@ehsandeep ehsandeep merged commit bdbc8e5 into projectdiscovery:dev Jan 22, 2026
9 of 10 checks passed
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.

5 participants