Event models silently drop fields that `event.json()` emits (`archive_url`, `reemit_source`, `envelopes`, `parent_uuid`)
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 58/100
Research direction
Start with bbot.core.event.base.BaseEvent.json(), the models in bbot.models.pydantic and bbot.models.sql, and test_db_models.py. Read how event fields are defined and how the existing round-trip test builds its fixtures. Done means both models preserve every field emitted by json() and the test covers those fields.
Written by the indexing model from the issue text.
Description
event.json() emits fields that BBOT's two event models don't declare. Both models use extra="ignore", so the fields disappear without an error:
| Model | Drops | Used by |
|---|---|---|
bbot.models.pydantic.Event |
archive_url, reemit_source, envelopes |
webhook, mongo |
bbot.models.sql.Event |
archive_url, reemit_source, envelopes, parent_uuid |
postgres, mysql, sqlite (via templates/sql.py) |
What gets lost:
archive_url: the Wayback snapshot an event's content came from. Thefrom-waybacktag survives, but not which snapshot.reemit_source: part of anHTTP_RESPONSE's id. When an event is rebuilt from these models, a response re-emitted byjs_unpackergets the id of the response it was unpacked from (output below).envelopes: how aWEB_PARAMETER's value is wrapped (base64, JSON and so on) and which sub-parameter it is. The sub-parameter is part of its id.parent_uuid(SQL only): which emission of the parent this event came from. Only the parent's id is kept.
The cause is that the event's JSON shape is written out by hand three times: in BaseEvent.json() and in each model. json() gained these fields and the models didn't. test_db_models.py round-trips json() through the pydantic model and would catch this, but none of its fixture events (ipv4, http_response, finding, storage_bucket) set these fields.
Reproduction
from bbot.scanner import Scanner
from bbot.core.event.base import event_from_json
from bbot.models.pydantic import Event as PydanticEvent
from bbot.models.sql import Event as SQLEvent
scan = Scanner("evilcorp.com", config={"dns": {"minimal": True}})
dns = scan.make_event("www.evilcorp.com", "DNS_NAME", parent=scan.root_event)
response = {"url": "https://www.evilcorp.com/app.js", "method": "GET", "status_code": 200,
"raw_header": "HTTP/1.1 200 OK\r\n\r\n", "archive_url": "https://web.archive.org/web/2020/https://www.evilcorp.com/app.js"}
wayback = scan.make_event(response, "HTTP_RESPONSE", parent=dns, tags=["from-wayback"])
unpacked = scan.make_event({k: v for k, v in response.items() if k != "archive_url"}, "HTTP_RESPONSE", parent=wayback, tags=["from-wayback"])
unpacked.reemit_source = "js_unpacker"
finding = scan.make_event({"name": "Secret", "description": "Secret found", "severity": "HIGH", "confidence": "HIGH",
"url": "https://www.evilcorp.com/app.js"}, "FINDING", parent=unpacked, tags=["from-wayback"])
param = scan.make_event({"host": "www.evilcorp.com", "url": "https://www.evilcorp.com/?q=1", "name": "q", "type": "GETPARAM",
"original_value": "1", "description": "d"}, "WEB_PARAMETER", parent=dns)
for e in (unpacked, finding, param):
j = e.json()
for model in (PydanticEvent, SQLEvent):
dumped = model(**j).model_dump(exclude_none=True)
print(f"{e.type:14} {model.__module__}.Event drops: {sorted(set(j) - set(dumped))}")
j = PydanticEvent(**unpacked.json()).model_dump(exclude_none=True)
print(f"\nreemitted HTTP_RESPONSE id: {unpacked.id}")
print(f"rebuilt from the pydantic model: {event_from_json(j).id}")
print(f"original (not reemitted) id: {wayback.id}")
HTTP_RESPONSE bbot.models.pydantic.Event drops: ['archive_url', 'reemit_source']
HTTP_RESPONSE bbot.models.sql.Event drops: ['archive_url', 'parent_uuid', 'reemit_source']
FINDING bbot.models.pydantic.Event drops: ['archive_url']
FINDING bbot.models.sql.Event drops: ['archive_url', 'parent_uuid']
WEB_PARAMETER bbot.models.pydantic.Event drops: ['envelopes']
WEB_PARAMETER bbot.models.sql.Event drops: ['envelopes', 'parent_uuid']
reemitted HTTP_RESPONSE id: HTTP_RESPONSE:58df7ea59c3871f50b3975fbb792eb69896794d0
rebuilt from the pydantic model: HTTP_RESPONSE:21a98504b05b747248e78b334e6bc192d0c2ffa7
original (not reemitted) id: HTTP_RESPONSE:21a98504b05b747248e78b334e6bc192d0c2ffa7
Proposed Behavior
- The event's JSON fields are defined once, and
json()and both models are built from that definition, so a field can't be added in one place and missed in the others. - The round-trip test covers every field
json()can emit, for both models, so a missing field fails CI.
- Dominant language
- Python
- Stars
- 10.9k
- Forks
- 959
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 84
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from blacklanternsecurity/bbot
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
blacklanternsecurity/bbot#3679 ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
blacklanternsecurity/bbot#3678 ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 28/100
blacklanternsecurity/bbot#3671 ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 22/100
blacklanternsecurity/bbot#3646 · 2 reactions ·
Maintainers usually reply within 2 days
-
Publish python deps for modules as optional depencency groupsPossibly taken @liquidsec claimed this 27 days ago. Openenhancement
blacklanternsecurity/bbot#3581 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
All issues in blacklanternsecurity/bbot
Similar issues
-
eegprep-lean: set channel types from the Zarr group's channel_typePossibly taken @claude claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
sccn/eegprep#668 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
Link Checker ReportOpenBot Type: Bug Type: Documentation
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
speakeasy-api/speakeasy#2159 ·
Maintainers usually reply within 1 day
-
area: ci enhancement perceived difficulty: 1
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Nitjsefnie-Harness-Commons/daedalus#1826 ·
Maintainers usually reply within 1 day