From 9ea94ed4fc801cfc672a0ea623522f1deabbeebf Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Wed, 26 Oct 2022 10:13:04 +0200 Subject: [PATCH] Explicitly copy folders before adding files This allows to protect copied files while additionally allowing learners to add new files in copied subdirectories --- lib/runner/strategy/poseidon.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/runner/strategy/poseidon.rb b/lib/runner/strategy/poseidon.rb index 88e2568b..26be670a 100644 --- a/lib/runner/strategy/poseidon.rb +++ b/lib/runner/strategy/poseidon.rb @@ -111,7 +111,15 @@ class Runner::Strategy::Poseidon < Runner::Strategy url = "#{runner_url}/files" Rails.logger.debug { "#{Time.zone.now.getutc.inspect}: Sending files to #{url}" } - copy = files.map do |file| + # First create all the directories to apply the sticky bit for additional protection + # See https://github.com/openHPI/poseidon/pull/240 + copy = files.uniq(&:path).filter_map do |file| + next if file.path.blank? + + {path: "#{file.path}/"} + end + + copy += files.map do |file| { path: file.filepath, content: Base64.strict_encode64(file.read || ''),