Skip to content

Commit c8489d4

Browse files
author
Shintaro Okamoto
committed
fix: add path traversal validation to style name parameters
Validate style name against [a-zA-Z0-9_-]+ in: - api/index.py get_style endpoint - mcp-server/server.py apply_style tool
1 parent 6ee9f31 commit c8489d4

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

‎api/index.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ def get_style(name: str) -> Dict[str, Any]:
245245
"""
246246
if not RESOURCE_BUCKET:
247247
return {"error": f"Style not found: {name}"}, 404
248+
if not re.fullmatch(r"[a-zA-Z0-9_-]+", name):
249+
return {"error": "Invalid style name"}, 400
248250
key = f"references/examples/styles/{name}.html"
249251
try:
250252
body = s3_client.get_object(Bucket=RESOURCE_BUCKET, Key=key)["Body"].read().decode("utf-8")

‎mcp-server/server.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import json
1616
import logging
1717
import os
18+
import re
1819
import sys
1920
from contextvars import ContextVar
2021
from pathlib import Path
@@ -359,6 +360,8 @@ def apply_style(deck_id: str, style: str) -> str:
359360
JSON confirmation.
360361
"""
361362
_check_deck_access(deck_id)
363+
if not re.fullmatch(r"[a-zA-Z0-9_-]+", style):
364+
raise ValueError("Invalid style name")
362365
html_key = f"references/examples/styles/{style}.html"
363366
html_bytes = _storage.download_file(key=html_key)
364367
dest_key = f"decks/{deck_id}/specs/art-direction.html"

0 commit comments

Comments
 (0)