fix: merge PythonFileUtils into PluginFsUtils

This commit is contained in:
Ian Chua
2026-07-16 20:40:32 +08:00
parent b779a7bfed
commit d9f8460a4e
18 changed files with 1051 additions and 1107 deletions

View File

@@ -2,11 +2,12 @@
#define slic3r_PluginAuditManager_hpp_
#include <Python.h>
#include <filesystem>
#include <mutex>
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
namespace Slic3r {
struct AuditDecision {
@@ -17,14 +18,14 @@ struct AuditDecision {
struct AuditViolation {
std::string plugin_key;
std::string event_name;
std::filesystem::path path;
boost::filesystem::path path;
std::string reason;
};
// Returns true if candidate resolves to a path inside allowed_root.
// Uses weakly_canonical and component-wise comparison to reject traversal attacks.
bool is_inside_allowed_root(const std::filesystem::path& candidate,
const std::filesystem::path& allowed_root);
bool is_inside_allowed_root(const boost::filesystem::path& candidate,
const boost::filesystem::path& allowed_root);
class PluginAuditManager
{
@@ -40,8 +41,8 @@ public:
void clear_current_plugin();
// --- allowed-roots registry ---
void add_global_allowed_root(const std::filesystem::path& root);
void add_scoped_allowed_root(const std::filesystem::path& root);
void add_global_allowed_root(const boost::filesystem::path& root);
void add_scoped_allowed_root(const boost::filesystem::path& root);
// --- enforcement mode ---
enum class AuditMode {
@@ -76,12 +77,12 @@ private:
static thread_local std::string m_current_plugin_key;
static thread_local AuditMode m_audit_mode;
static thread_local std::vector<std::filesystem::path> m_scoped_allowed_roots;
static thread_local std::vector<boost::filesystem::path> m_scoped_allowed_roots;
static thread_local bool m_has_last_violation;
static thread_local AuditViolation m_last_violation;
std::mutex m_mutex;
std::vector<std::filesystem::path> m_global_allowed_roots;
std::vector<boost::filesystem::path> m_global_allowed_roots;
};
// RAII guard that sets the current plugin key and restores the previous one.
@@ -100,7 +101,7 @@ public:
private:
std::string m_previous_id;
PluginAuditManager::AuditMode m_previous_mode;
std::vector<std::filesystem::path> m_previous_scoped_roots;
std::vector<boost::filesystem::path> m_previous_scoped_roots;
};
} // namespace Slic3r