fix: API route security fixes (path traversal, auth, bare except)

- articles.py: Path traversal sanitization
- optimizer_logs.py: Admin auth guard
- platform_config.py: Admin auth guard
- system.py: Path traversal whitelist
- topic_config.py: Admin auth guard
- topics.py: Minor fix

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Yuzhiran Dev
2026-06-16 08:23:50 +08:00
parent 8595bbc521
commit d601a26850
6 changed files with 33 additions and 18 deletions
@@ -1,3 +1,4 @@
import re
from fastapi import APIRouter, Depends, HTTPException, Request
from sqlalchemy.orm import Session
from pathlib import Path
@@ -58,6 +59,11 @@ def get_logs(
"""
if not type or not date:
raise HTTPException(status_code=400, detail="type and date parameters are required")
_ALLOWED_LOG_TYPES = {"creator", "collector", "optimizer", "sources", "metrics", "trends", "rank_tracker"}
if type not in _ALLOWED_LOG_TYPES:
raise HTTPException(status_code=400, detail=f"Invalid log type: {type}")
if not re.match(r'^\d{4}-\d{2}-\d{2}$', date):
raise HTTPException(status_code=400, detail="Invalid date format (expected YYYY-MM-DD)")
logs_dir = PROJECT_ROOT / "automation" / "logs"
filename = f"{type}_{date}.log"
log_path = logs_dir / filename