Address the four P0 security items from the project review: * token_version validation (#1): the JWT middleware now rejects access tokens whose token_version claim is stale (e.g. issued before a password change). A short-TTL (30s) in-memory cache (TokenVersionCache) avoids a Mongo lookup per request; credential changes invalidate the cache immediately on the handling instance. * Fail-fast config (#2): add APP_ENVIRONMENT (development|production). In production the server refuses to boot unless JWT_SECRET and ENCRYPTION_KEY are set to non-default values; development keeps the insecure defaults with a warning. * Real client IP in audit logs (#4): new client_ip middleware resolves the originating IP (X-Forwarded-For > X-Real-IP > ConnectInfo socket) and exposes it via a ClientIp extractor. All five hardcoded "0.0.0.0" audit calls are replaced, and the missing PasswordChanged audit event is added to change_password. axum::serve now uses into_make_service_with_connect_info. * Refresh token persistence (#5): refresh tokens are now stored hashed in MongoDB (RefreshTokenRepository) instead of an in-memory map lost on restart. Added /api/auth/refresh (with rotation + token_version check) and /api/auth/logout routes; register/login return a refresh_token; password change/recovery revoke all of a user's refresh tokens. JwtService now honors JwtConfig expiries instead of hardcoding 15min/30d, and the dead in-memory refresh store is removed. Also: wire up DatabaseInitializer (was never called), fix the refresh_tokens index to tokenHash + add an expiresAt TTL index, add sha2 dep. Rate limiting (#3) is deferred per scope; the stub remains. Verified: cargo fmt --check clean, cargo build/clippy --all-targets clean, 18 unit tests pass (9 new). Integration tests (tests/*) still need a live server — fixing them is tracked as P1. BREAKING CHANGE: AuthResponse now includes a refresh_token field.
28 lines
990 B
Rust
28 lines
990 B
Rust
pub mod auth;
|
|
pub mod health;
|
|
pub mod health_stats;
|
|
pub mod interactions;
|
|
pub mod medications;
|
|
pub mod permissions;
|
|
pub mod sessions;
|
|
pub mod shares;
|
|
pub mod users;
|
|
|
|
// Re-export commonly used handler functions
|
|
pub use auth::{login, logout, recover_password, refresh, register};
|
|
pub use health::{health_check, ready_check};
|
|
pub use health_stats::{
|
|
create_health_stat, delete_health_stat, get_health_stat, get_health_trends, list_health_stats,
|
|
update_health_stat,
|
|
};
|
|
pub use interactions::{check_interactions, check_new_medication};
|
|
pub use medications::{
|
|
create_medication, delete_medication, get_adherence, get_medication, list_medications,
|
|
log_dose, update_medication,
|
|
};
|
|
pub use permissions::check_permission;
|
|
pub use sessions::{get_sessions, revoke_all_sessions, revoke_session};
|
|
pub use shares::{create_share, delete_share, list_shares, update_share};
|
|
pub use users::{
|
|
change_password, delete_account, get_profile, get_settings, update_profile, update_settings,
|
|
};
|