Nettacker icon indicating copy to clipboard operation
Nettacker copied to clipboard

create_dd_specific_json() crashes with AttributeError when generating DefectDojo (.dd.json) reports on SQLite/APSW

Open shikhabhadoria opened this issue 3 weeks ago • 2 comments

Description

When generating a DefectDojo report (-o report.dd.json), create_report() in nettacker/core/graph.py (lines 228, 282–285) fetches scan events via get_logs_by_scan_id(scan_id) and passes them to create_dd_specific_json(all_scan_logs).

In nettacker/database/db.py (lines 775–805), get_logs_by_scan_id(scan_id) returns different types for json_event depending on the database backend:

  • SQLite with APSW (default, line 783): "json_event": json.loads(row[6]) if row[6] else {} (a dict)
  • SQLAlchemy (line 802): "json_event": log.json_event (a str)

However, create_dd_specific_json() in nettacker/core/graph.py (line 134) assumes log["json_event"] is always a str and calls .strip() on it:

for log in all_scan_logs:
    module_name = log["module_name"].strip()
    date = datetime.strptime(log["date"], "%Y-%m-%d %H:%M:%S.%f").strftime("%m/%d/%Y")
    port = str(log.get("port", "")).strip()
    impact = log.get("event", "").strip()
    severity_justification = log.get("json_event", "").strip()

Under the default SQLite/APSW backend, log.get("json_event", "") is a dict, so .strip() always raises:

AttributeError: 'dict' object has no attribute 'strip'

(The existing unit test in tests/unit/core/test_graph.py mocked get_logs_by_scan_id with "json_event": "{}" as a string, which masked this crash.)

Proof / Reproduction

from nettacker.core.graph import create_dd_specific_json

# Structure returned by get_logs_by_scan_id() in nettacker/database/db.py:776-784 (APSW default)
scan_logs = [
    {
        "scan_id": "abc123",
        "target": "example.com",
        "module_name": "http_status_scan",
        "date": "2026-11-12 04:55:01.123456",
        "port": 80,
        "event": "status_code: 200",
        "json_event": {"port": 80, "response": {"conditions_results": {"status_code": ["200"]}}},
    }
]

create_dd_specific_json(scan_logs)

Traceback:

File "nettacker/core/graph.py", line 134, in create_dd_specific_json
    severity_justification = log.get("json_event", "").strip()
AttributeError: 'dict' object has no attribute 'strip'

Proposed Fix

Normalize json_event consistently (e.g. serialize dict values with json.dumps(...) or return consistent types in get_logs_by_scan_id()) before calling .strip() in create_dd_specific_json(), and add a unit test in tests/unit/core/test_graph.py covering dict-typed json_event records as returned by the APSW backend.

Hi @securestep9 @arkid15r, could you please assign this issue to me?


OS: Linux

OS Version: Ubuntu 22.04

Python Version: 3.11

shikhabhadoria avatar Nov 12 '26 05:11 shikhabhadoria

Hi maintainers, I'd like to work on these issues. I have PR #1874 ready with fixes. Could you please assign these issues to me so I can proceed? My commits are now GPG-signed and ready for review.

Thanks!

user-Param avatar Nov 12 '26 11:11 user-Param

@arkid15r @securestep9 Hi, I'd like to work on this issue. I have a fix ready with PR #1874 open. Could you please assign this issue to me so I can proceed? My commits are now GPG-signed and ready for review.

Thanks!

user-Param avatar Nov 12 '26 11:11 user-Param