Skip to content

Commit 1bd52b9

Browse files
committed
fix: block private repos + fix stale cache TTL comments
1. Security: reject private repos with 403 before fetching directory tree. Server GITHUB_TOKEN could access private repos via GitHub API, which would leak private repo structure to unauthenticated /analyze callers. Same check the playground validation already does. 2. Fix stale comments that said '5 minutes' when TTL was bumped to 24 hours. 25 tests pass.
1 parent 2535cd8 commit 1bd52b9

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

backend/routes/repos.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ async def analyze_repository(request: AnalyzeRepoRequest) -> dict:
319319
Returns directory tree with file counts so the user can select
320320
which directories to index (monorepo subset selection).
321321
322-
Results are cached for 5 minutes to avoid redundant GitHub API calls.
322+
Results are cached for 24 hours (see _ANALYZE_CACHE_TTL) since
323+
directory structure rarely changes.
323324
"""
324325
match = _GITHUB_URL_RE.match(request.github_url)
325326
if not match:
@@ -359,6 +360,15 @@ async def analyze_repository(request: AnalyzeRepoRequest) -> dict:
359360
metadata = meta_resp.json()
360361
except ValueError:
361362
raise HTTPException(status_code=502, detail="Invalid response from GitHub API")
363+
364+
# Block private repos -- server GITHUB_TOKEN could access them,
365+
# but we must not leak private repo structure to unauthenticated callers
366+
if metadata.get("private", False):
367+
raise HTTPException(
368+
status_code=403,
369+
detail="Private repositories are not supported. Use authenticated indexing instead.",
370+
)
371+
362372
default_branch = metadata.get("default_branch", "main")
363373

364374
# 2. Fetch directory tree (reuse same client)
@@ -389,7 +399,7 @@ async def analyze_repository(request: AnalyzeRepoRequest) -> dict:
389399
**tree_data,
390400
}
391401

392-
# Cache for 5 minutes
402+
# Cache result
393403
if cache:
394404
cache.set(cache_key, result, ttl=_ANALYZE_CACHE_TTL)
395405

0 commit comments

Comments
 (0)