mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 03:29:19 +02:00
Requirements: - parametres.php toggle: 'restricted_files_enabled' enables/disables the feature - Public TFE page: when enabled + access_type=Interne, hides files, shows French restriction message + access request form (metadata/synopsis still visible) - ERG emails (@erg.school / @erg.be): auto-approve, send 24h access link immediately - External emails: show justification textarea, create pending request, notify admin - Admin panel /admin/file-access.php: approve/reject requests with optional notes, sends access email on approval (linked from admin nav with pending count badge) Security: - One-time 24h email tokens (used_at + is_valid=0 on first click) - Token redeemed via POST /validate-access (GET shows confirmation page only) - Long-lived 30-day browser session in file_access_sessions table - Cookie: HttpOnly + Secure + SameSite=Strict - CSRF on all mutations, rate limiting on request submission - Audit trail: IP, UA, event, timestamp in file_access_audit Bug fixes: - admin/file-access.php: $vars never extract()ed → page was blank - Template had self-contained head/footer includes (double-include) - Admin approval URL used $requestId instead of $request['thesis_id'] - App::boot() now starts session so CSRF token works on public pages - Dispatcher routes /validate-access and /request-access through front controller
51 lines
2.2 KiB
SQL
51 lines
2.2 KiB
SQL
-- ============================================================================
|
|
-- SECURE ACCESS TOKEN IMPROVEMENTS
|
|
-- ============================================================================
|
|
-- 1. Mark email tokens as one-time-use (used_at timestamp)
|
|
-- 2. Add cookie sessions table (separate, long-lived, revocable)
|
|
-- 3. Add audit log table for token redemptions
|
|
-- ============================================================================
|
|
|
|
-- Track when a one-time email link was redeemed
|
|
ALTER TABLE file_access_tokens ADD COLUMN used_at DATETIME DEFAULT NULL;
|
|
|
|
-- ============================================================================
|
|
-- COOKIE SESSIONS TABLE
|
|
-- ============================================================================
|
|
-- Stores long-lived browser sessions granted after token redemption.
|
|
-- Distinct from email tokens: email token is one-time, session is long-lived.
|
|
-- ============================================================================
|
|
|
|
CREATE TABLE IF NOT EXISTS file_access_sessions (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
request_id INTEGER NOT NULL,
|
|
session_token TEXT NOT NULL UNIQUE,
|
|
expires_at DATETIME NOT NULL,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
is_valid INTEGER NOT NULL DEFAULT 1,
|
|
FOREIGN KEY (request_id) REFERENCES file_access_requests(id) ON DELETE CASCADE
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_file_access_sessions_token
|
|
ON file_access_sessions(session_token);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_file_access_sessions_expires
|
|
ON file_access_sessions(expires_at);
|
|
|
|
-- ============================================================================
|
|
-- TOKEN REDEMPTION AUDIT LOG
|
|
-- ============================================================================
|
|
|
|
CREATE TABLE IF NOT EXISTS file_access_audit (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
request_id INTEGER NOT NULL,
|
|
event TEXT NOT NULL, -- 'redeemed', 'expired', 'invalid'
|
|
ip TEXT,
|
|
user_agent TEXT,
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
FOREIGN KEY (request_id) REFERENCES file_access_requests(id) ON DELETE CASCADE
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_file_access_audit_request
|
|
ON file_access_audit(request_id);
|