diff --git a/app/sovran_systemsos_web/server.py b/app/sovran_systemsos_web/server.py index fce2989..5311278 100644 --- a/app/sovran_systemsos_web/server.py +++ b/app/sovran_systemsos_web/server.py @@ -4529,6 +4529,16 @@ async def api_domains_set(req: DomainSetRequest): _ensure_domains_dir() domain_path = os.path.join(DOMAINS_DIR, req.domain_name) + # --- CodeQL path-injection fix --- + # _validate_safe_name already enforces ^[a-zA-Z0-9_-]+$, but CodeQL + # does not recognize it as a sanitizer. Add explicit checks that + # CodeQL *does* recognize: basename equality and commonpath containment. + if os.path.basename(domain_path) != req.domain_name: + raise HTTPException(status_code=400, detail="Invalid domain_name") + # Ensure the final path is still inside DOMAINS_DIR (prevents ../ traversal) + # Use normpath + commonpath — recognized by py/path-injection query. + if os.path.commonpath([os.path.normpath(DOMAINS_DIR), os.path.normpath(domain_path)]) != os.path.normpath(DOMAINS_DIR): + raise HTTPException(status_code=400, detail="Invalid domain_name") with open(domain_path, "w") as f: f.write(normalized) _chown_to_caddy(domain_path)