fix: serialize HTTP headers as JSON so tool detection and bounty extraction work

templates/decnet_logging.py calls str(v) on all SD-PARAM values, turning a
headers dict into Python repr ('{'User-Agent': ...}') rather than JSON.
detect_tools_from_headers() called json.loads() on that string and silently
swallowed the error, returning [] for every HTTP event. Same bug prevented
the ingester from extracting User-Agent bounty fingerprints.

- templates/http/server.py: wrap headers dict in json.dumps() before passing
  to syslog_line so the value is a valid JSON string in the syslog record
- behavioral.py: add ast.literal_eval fallback for existing DB rows that were
  stored with the old Python repr format
- ingester.py: parse headers as JSON string in _extract_bounty so User-Agent
  fingerprints are stored correctly going forward
- tests: add test_json_string_headers and test_python_repr_headers_fallback
  to exercise both formats in detect_tools_from_headers
This commit is contained in:
2026-04-15 17:03:52 -04:00
parent 02e73a19d5
commit 89887ec6fd
4 changed files with 38 additions and 4 deletions

View File

@@ -79,7 +79,7 @@ def log_request():
method=request.method,
path=request.path,
remote_addr=request.remote_addr,
headers=dict(request.headers),
headers=json.dumps(dict(request.headers)),
body=request.get_data(as_text=True)[:512],
)