* \brief Resolve a scene-relative path against \p basePath. * * Absolute paths are returned as-is. Relative paths are joined to * \p basePath and lexically normalised, so `..` segments are allowed * and collapsed against the scene directory's own path. A warning is * logged whenever the resolved path falls outside \p basePath * (absolute paths or `..` traversal that escapes the s
| 122 | * not loading scenes from untrusted sources. |
| 123 | */ |
| 124 | fs::path ResolvePath(const fs::path &basePath, const std::string &relativeOrAbsolute) |
| 125 | { |
| 126 | const fs::path p(relativeOrAbsolute); |
| 127 | if (p.is_absolute()) |
| 128 | { |
| 129 | MITK_WARN << "Scene references absolute path '" << p.string() |
| 130 | << "' which is outside the scene directory '" << basePath.string() |
| 131 | << "'. Loading anyway - only load scene files from trusted sources."; |
| 132 | return p; |
| 133 | } |
| 134 | const fs::path resolved = (basePath / p).lexically_normal(); |
| 135 | const fs::path normalizedBase = basePath.lexically_normal(); |
| 136 | const fs::path relative = resolved.lexically_relative(normalizedBase); |
| 137 | if (!relative.empty() && relative.begin() != relative.end() && *relative.begin() == fs::path("..")) |
| 138 | { |
| 139 | MITK_WARN << "Scene path '" << relativeOrAbsolute |
| 140 | << "' resolves outside the scene directory '" << normalizedBase.string() |
| 141 | << "' (resolved: '" << resolved.string() |
| 142 | << "'). Loading anyway - only load scene files from trusted sources."; |
| 143 | } |
| 144 | return resolved; |
| 145 | } |
| 146 | |
| 147 | void WarnUnknownKeys(const json &obj, const std::set<std::string> &known, const std::string &context) |
| 148 | { |
no test coverage detected