-
Notifications
You must be signed in to change notification settings - Fork 0
Add UUID format validation for progress tokens before store lookup #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |||||||||
| from novelforge.llm.client import call_llm, parse_llm_json, friendly_llm_error | ||||||||||
| from novelforge.llm.image import call_image_api | ||||||||||
| from novelforge.agents.chapter import build_illustration_prompt_generator_prompt | ||||||||||
| from novelforge.routes.generation._shared import _is_valid_token | ||||||||||
|
|
||||||||||
| logger = logging.getLogger(__name__) | ||||||||||
|
|
||||||||||
|
|
@@ -105,6 +106,9 @@ def export_novel() -> Response | tuple[Response, int]: | |||||||||
| data = request.get_json(silent=True) or {} | ||||||||||
| token = data.get("token", "") | ||||||||||
|
|
||||||||||
| if not _is_valid_token(token): | ||||||||||
| return jsonify({"error": "Invalid progress token."}), 400 | ||||||||||
|
|
||||||||||
| progress_data = progress_manager.get(token) | ||||||||||
|
|
||||||||||
| if not progress_data or progress_data.get("status") != "done": | ||||||||||
|
|
@@ -130,6 +134,9 @@ def export_editors_notes() -> Response | tuple[Response, int]: | |||||||||
| data = request.get_json(silent=True) or {} | ||||||||||
| token = data.get("token", "") | ||||||||||
|
|
||||||||||
|
||||||||||
| if not token: | |
| return jsonify({"error": "Missing progress token."}), 400 |
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the other export endpoints: missing token (no "token" field) becomes "" and is reported as “Invalid progress token.”. If you want to preserve the existing “Missing progress token.” semantics used elsewhere, add a separate empty check before _is_valid_token().
| if not token: | |
| return jsonify({"error": "Missing progress token."}), 400 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,22 @@ | ||
| """Shared state for the generation route package.""" | ||
|
|
||
| import re | ||
|
|
||
| from flask import Blueprint | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Progress-token validation | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| _UUID_RE = re.compile( | ||
| r'^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' | ||
| ) | ||
|
|
||
|
|
||
| def _is_valid_token(token: str) -> bool: | ||
| """Return True iff *token* matches the UUID v4 format used by this app.""" | ||
| return bool(token and _UUID_RE.match(token)) | ||
|
Comment on lines
+11
to
+18
|
||
|
|
||
| generation_bp = Blueprint("generation", __name__) | ||
|
|
||
| # Minimum seconds between time-based progress snapshot persists. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These routes now treat a missing/empty token (default "") as “Invalid progress token.” while other endpoints (e.g., /revise_chapter) return “Missing progress token.” for the same condition. Consider adding an explicit
if not token: ... Missing progress token ...guard before format validation to keep API error semantics consistent.