From f672ded04c03a0984f10499684355caecfdfb54b Mon Sep 17 00:00:00 2001 From: salman Date: Thu, 19 Nov 2026 21:29:43 +0100 Subject: [PATCH] Resolve portable run paths for web metadata --- cgi/single_musrfit.cgi | 9 ++++++++- tests/cgi-hardening.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cgi/single_musrfit.cgi b/cgi/single_musrfit.cgi index cd86fb1..ea6d28e 100755 --- a/cgi/single_musrfit.cgi +++ b/cgi/single_musrfit.cgi @@ -2091,9 +2091,16 @@ if ($action eq "dump_header") { if ($file_format !~ /^(?:MusrRoot|NeXus|ROOT|PSI-BIN|PSI-MDU|MUD|WKM)$/) { respond_json({ ok => JSON::PP::false, code => 400, message => "Invalid data-file format" }); } - if (!path_is_under_data_root($data_file)) { + # Web RUN directives may use a portable path relative to a startup-XML + # . Resolve it through the same bounded path resolver used by + # series inventory before invoking dump_header. This keeps metadata lookup + # consistent with musrfit without accepting arbitrary server paths. + my $resolved_data_file = path_is_under_data_root($data_file) + ? $data_file : series_data_file_root($data_file); + if (!defined($resolved_data_file)) { respond_json({ ok => JSON::PP::false, code => 400, message => "Invalid data-file path" }); } + $data_file = $resolved_data_file; if (!-f $data_file) { respond_json({ ok => JSON::PP::false, code => 404, message => "Data file not found" }); } diff --git a/tests/cgi-hardening.test.js b/tests/cgi-hardening.test.js index 1915f76..4d0aabe 100644 --- a/tests/cgi-hardening.test.js +++ b/tests/cgi-hardening.test.js @@ -140,6 +140,30 @@ try { assert.strictEqual(res.message, "Invalid data-file path"); } + // 4b. Portable RUN names resolve through administrator-owned startup XML + // data paths, matching abbreviated names used by browser Fit/Plot. + { + const portableRoot = path.join(testRoot, "portable-data"); + const portableFile = path.join(portableRoot, "2026", "lem26_his_1200.root"); + const startupXml = path.join(testRoot, "musrfit_startup.xml"); + fs.mkdirSync(path.dirname(portableFile), { recursive: true }); + fs.writeFileSync(portableFile, "dummy"); + fs.writeFileSync(startupXml, [ + "", + " " + portableRoot + "", + "", + "" + ].join("\n")); + const res = runCGI(new URLSearchParams({ + action: "dump_header", + fn: "2026/lem26_his_1200.root", + file_format: "MusrRoot" + }).toString(), { MUSRFIT_STARTUP_XML: startupXml }); + assert.strictEqual(res.ok, true); + assert.strictEqual(res.code, 0); + assert.match(res.header, /RUN 514/); + } + // 5. dump_header hangs are bounded by the watchdog. The fake records its // pid and sleeps; the CGI must return a timeout well before the sleep // finishes and must kill the child process.