Conversation
csd113
added a commit
that referenced
this pull request
Mar 18, 2026
## Fix: backup validation, logging rotation, and DB consistency improvements This PR completes updates to `backup.rs` and `logging.rs`, along with several fixes across the database layer. --- ### Summary of Changes #### `db/posts.rs` - **#13 – Constant-time comparison** - Replaced custom `constant_time_eq` with `subtle::ConstantTimeEq` - Use: `a.ct_eq(b).into()` - Added import: `use subtle::ConstantTimeEq as _` - Removed hand-rolled implementation - **#16 – Poll vote race condition** - Updated `cast_vote` query: - JOINs `polls` table - Adds expiry guard: ```sql AND (p.expires_at IS NULL OR p.expires_at > unixepoch()) ``` - Prevents race between handler validation and INSERT - **#25 – `edit_window_secs` semantics** - `0` → no time limit (skips check via `Option`) - Negative → fallback to 300s - Positive → used as-is --- #### `handlers/admin/backup.rs` - **#19 – SQLite validation** - Added magic byte check (`b"SQLite format 3\0"`) after extracting `chan.db` - Applied to: - `admin_restore` - `restore_saved_board_backup` - Invalid DB now returns `400 Bad Request` before `rusqlite` usage - **#30 – Duplicate encoding logic removed** - Removed inner `encode_q` / `nibble` definitions - Introduced single module-level `encode_q` - Shared across: - `admin_restore` - `restore_saved_board_backup` - `board_restore` --- #### `db/logging.rs` (moved from `logging.rs`) - **#33 – Log rotation** - Replaced `rolling::never` with `rolling::daily` - Logs now rotate automatically: ``` rustchan.log.YYYY-MM-DD ``` - **Location + API updates** - Moved file to: `db/logging.rs` - Renamed `log_dir` → `db_dir` - Logs now stored alongside `chan.db` - Updated documentation accordingly --- ### Required Follow-ups - Update module declaration: ```rust // db/mod.rs pub mod logging;
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.