lighthouse: add local fixes and exploit tooling

This commit is contained in:
shira committed 2026-10-25 10:56:50 +03:00
1 parent 21a8646fd9
commit 8987f08ee1
11 files changed
+935 -30

No files matched your search

+9 -3
View File
@@ -1,5 +1,6 @@
#pragma once
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <mutex>
@@ -15,13 +16,18 @@ inline void append(const std::string& created_at, const std::string& queue,
std::lock_guard guard(lock);
auto directory = std::filesystem::path("/var/log/lighthouse") / created_at.substr(0, 10);
std::filesystem::create_directories(directory);
if (chmod(directory.c_str(), 0755) != 0)
if (chmod(directory.c_str(), 0700) != 0)
throw std::runtime_error("cannot secure journal directory");
auto path = directory / (queue + ".log");
std::ofstream file(path, std::ios::app);
if (!file || chmod(path.c_str(), 0644) != 0)
if (!file || chmod(path.c_str(), 0600) != 0)
throw std::runtime_error("cannot open journal");
file << instant << " queue=" << queue << " topic=" << topic << " ciphertext=" << cipher << "\n";
const auto line = instant + " queue=" + queue + " topic=" + topic + " ciphertext=" + cipher + "\n";
const auto position = file.tellp();
if (position < 0) throw std::runtime_error("cannot size journal");
constexpr std::uintmax_t max_journal_bytes = 512 * 1024;
if (static_cast<std::uintmax_t>(position) + line.size() > max_journal_bytes) return;
file << line;
file.close();
if (!file) throw std::runtime_error("cannot write journal");
}