Skip to content

Commit b94aa8a

Browse files
committed
envelope event_id check: on-parse
1 parent 2c41fbe commit b94aa8a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ingest/filestore.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ def get_filename_for_event_id(event_id):
88
# implemented. However, counterpoint: when doing stress tests, it was quite hard to get a serious backlog going
99
# (snappea was very well able to play catch-up). So this might not be necessary.
1010

11-
# ensure that event_id is a uuid, and remove dashes if present
11+
# ensure that event_id is a uuid, and remove dashes if present; also doubles as a security-check (event_id is
12+
# user-provided (but at this point already validated to be a valid UUID), but b/c of the below the
13+
# security-implications of os.path.join can be understood right here in the code without needing to inspect all
14+
# call-sites).
1215
event_id_normalized = uuid.UUID(event_id).hex
1316

1417
return os.path.join(get_settings().INGEST_STORE_BASE_DIR, event_id_normalized)

ingest/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import uuid
12
import hashlib
23
import os
34
import logging
@@ -618,6 +619,13 @@ def factory(item_headers):
618619
# payload's event_id), so we can rely on it having been set.
619620
if "event_id" not in envelope_headers:
620621
raise ParseError("event_id not found in envelope headers")
622+
623+
try:
624+
# validate that the event_id is a valid UUID as per the spec (validate at the edge)
625+
uuid.UUID(envelope_headers["event_id"])
626+
except ValueError:
627+
raise ParseError("event_id in envelope headers is not a valid UUID")
628+
621629
filename = get_filename_for_event_id(envelope_headers["event_id"])
622630
os.makedirs(os.path.dirname(filename), exist_ok=True)
623631
return MaxDataWriter("MAX_EVENT_SIZE", open(filename, 'wb'))

0 commit comments

Comments
 (0)