Skip to content

fix(nmap): handle hosts without optional hostnames element (#16410) - #16872

Open
sakhi383 wants to merge 1 commit into
DefectDojo:devfrom
sakhi383:fix/nmap-optional-hostnames
Open

sakhi383 wants to merge 1 commit into
DefectDojo:devfrom
sakhi383:fix/nmap-optional-hostnames

Conversation

@sakhi383

@sakhi383 sakhi383 commented Nov 13, 2026 •

Copy link
Copy Markdown

Description

Fixes #16410.

When importing an Nmap XML scan report where one or more hosts do not have a <hostnames> element (e.g. scanning an IP address directly with -n or where reverse DNS lookup is unavailable/skipped), dojo/tools/nmap/parser.py crashed with:

TypeError: 'NoneType' object is not iterable

This occurred because host.find("hostnames") was iterated over unconditionally, returning None when the element is absent.

Changes

  1. Added a None check before iterating over host.find("hostnames") in dojo/tools/nmap/parser.py.
  2. Added defensive fallback for IP address extraction supporting address[@addrtype='ipv6'] and generic address attributes without throwing AttributeError.
  3. Added sample scan file unittests/scans/nmap/issue16410.xml and automated unit test test_parse_issue16410 in unittests/tools/test_nmap_parser.py.

Test results

  • Executed TestNmapParser.test_parse_issue16410, verifying that Nmap scans without hostname elements import cleanly into findings with correct endpoints and port numbers.
  • Verified test suite passes without regressions.

Checklist

  • Make sure to rebase your PR against the very latest dev.
  • Submit all PRs, features and bug fixes alike, against the dev branch.
  • Give a meaningful name to your PR, as it may end up being used in the release notes.
  • Add applicable tests to the unit tests.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant