Check upload names before writing files

C++ · C++ · intermediate · modification

Until now `put_file` joined the client's name onto the upload root as is, so a name like `../../etc/cron.d/job` could be written outside the root. This PR adds `uploads::resolve_store_path` (`store_path.hpp`, `store_path.cpp`): it checks the name against the naming rules segment by segment, builds the relative path from the accepted segments, resolves the root and the joined path through any symlinks (the root must exist, the joined path need not), compares the two element by element so the result must lie strictly below the root, and then walks the elements below the root with `symlink_status`, up to the first one that does not exist, refusing a symlink among them. `put_file.cpp` calls it first and answers `400` when it returns nothing; the directory creation and the write are as before. `tests/store_path_test.cpp` builds a scratch tree in the temp directory (an `uploads` root with an `uploads2` sibling) and covers accepted names, refused names, symlinks inside the root and `put_file` end to end.

Internal document drop service in C++20, standard library only, built with CMake (build files unchanged; they pick up every `src/**/*.cpp` and every `tests/*_test.cpp`) by Apple clang 17 locally and GCC 13 in CI with `-Wall -Wextra -Wconversion` treated as errors. Runs on Linux (ext4) in production. The HTTP layer (existing, not in the diff) percent-decodes the path after `/files/` and passes it to `put_file` as raw bytes, caps bodies at 64 MiB, and handles requests one at a time on a single worker thread. `UploadConfig::root` is an absolute path of under 200 bytes from the service's config file; it may itself be a symlink, it is created at deploy time, exists while the service runs, and only the service's user can write to it. Besides the directories and files this service writes, the root holds only symlinks that operators create while the service is stopped (for example a `shared` link to a team share outside the root); no other process writes under the root while the service runs. Tests use the repo's existing helper `tests/check.hpp` (unchanged): `TEST(name)` registers a test, `CHECK(expr)` and `CHECK_EQ(a, b)` record a failure without stopping, and `tests/check_main.cpp` runs every registered test and exits non-zero on any failure.

Requirements

Files touched

Review this PR

C++ practice