File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -135,6 +135,26 @@ def _generate_random_arc_id() -> str:
135135
136136 now = datetime .now (UTC ).isoformat ()
137137 arc_dir = output_path / arc_id
138+
139+ # Ensure the resolved target directory stays within the intended output root.
140+ output_root_resolved = output_path .resolve ()
141+ arc_dir_resolved = arc_dir .resolve ()
142+ common_root = Path (os .path .commonpath ([str (output_root_resolved ), str (arc_dir_resolved )]))
143+ if common_root != output_root_resolved :
144+ # Reject paths that would escape the output root (for example via symlinks).
145+ return {
146+ "arc_id" : arc_id ,
147+ "status" : "error" ,
148+ "metadata" : {
149+ "rdi" : rdi ,
150+ "arc_hash" : "demo_hash" ,
151+ "status" : "REJECTED" ,
152+ "first_seen" : now ,
153+ "last_seen" : now ,
154+ },
155+ }
156+
157+ arc_dir = arc_dir_resolved
138158 payload_path = arc_dir .with_suffix (".payload.json" )
139159
140160 with open (payload_path , "w" , encoding = "utf-8" ) as handle :
You can’t perform that action at this time.
0 commit comments