File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,10 @@ def get_filename_for_event_id(event_id):
8
8
# implemented. However, counterpoint: when doing stress tests, it was quite hard to get a serious backlog going
9
9
# (snappea was very well able to play catch-up). So this might not be necessary.
10
10
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).
12
15
event_id_normalized = uuid .UUID (event_id ).hex
13
16
14
17
return os .path .join (get_settings ().INGEST_STORE_BASE_DIR , event_id_normalized )
Original file line number Diff line number Diff line change
1
+ import uuid
1
2
import hashlib
2
3
import os
3
4
import logging
@@ -618,6 +619,13 @@ def factory(item_headers):
618
619
# payload's event_id), so we can rely on it having been set.
619
620
if "event_id" not in envelope_headers :
620
621
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
+
621
629
filename = get_filename_for_event_id (envelope_headers ["event_id" ])
622
630
os .makedirs (os .path .dirname (filename ), exist_ok = True )
623
631
return MaxDataWriter ("MAX_EVENT_SIZE" , open (filename , 'wb' ))
You can’t perform that action at this time.
0 commit comments