Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@
**Vulnerability:** The `ExplainRequest`, `ChatRequest`, and `GhostNarrateRequest` Pydantic models lacked LLM input sanitization (`sanitize_llm_input`) for the string list parameters (`callers`, `callees`, `neighbors`, `context_nodes`). These fields were only validated for maximum length. Without applying standard regex filtering via `sanitize_llm_input`, an attacker could potentially execute a prompt injection attack through these context node identifiers when they are serialized into backend LLM prompts.
**Learning:** Pydantic validators (`@field_validator`) for complex types (like lists of strings) must iterate and individually apply sanitization filters to every element, just as scalar string fields do. Relying solely on `max_length` prevents DoS but does not prevent logic/injection attacks if special characters remain unsanitized.
**Prevention:** Always apply the standard `sanitize_llm_input` function to every string passed into LLM prompts, even if those strings are nested inside list or dictionary parameters.
## 2024-05-31 - [Normalize uploaded filename uses unified sensitivity check]
**Vulnerability:** The `normalize_uploaded_filename` utility checked for sensitive names (e.g. `.env`, `.git`) but was missing checks for some keys (e.g., `id_rsa`, `.pem`) that were present in the centralized `_contains_sensitive_segment`. This allowed these files to be uploaded.
**Learning:** Defense mechanisms (like sensitive file blocklists) that have a robust centralized check (`_contains_sensitive_segment`) should be utilized everywhere paths are parsed to prevent discrepancy between code paths.
**Prevention:** Unify validation logic by replacing inline subset checks with the robust `_contains_sensitive_segment` utility.
16 changes: 7 additions & 9 deletions app/utils/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,14 @@ def normalize_uploaded_filename(raw_name: str | None) -> str:
if ".." in parts:
raise HTTPException(status_code=400, detail=f"Unsafe upload path: {raw_name}")

sensitive_names = {".env", ".git", ".ssh", ".aws", ".npmrc", ".pypirc", ".netrc"}
for part in parts:
part_lower = part.lower()
if part_lower.startswith(".env") or part_lower in sensitive_names:
raise HTTPException(
status_code=400,
detail=f"Sensitive hidden file or directory not allowed: {part}",
)

safe_rel = "/".join(parts)

if _contains_sensitive_segment(safe_rel):
raise HTTPException(
status_code=400,
detail=f"Sensitive hidden file or directory not allowed in path: {raw_name}",
)

if os.path.isabs(safe_rel):
raise HTTPException(status_code=400, detail=f"Unsafe upload path: {raw_name}")

Expand Down
2 changes: 2 additions & 0 deletions tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def test_normalize_uploaded_filename_blocks_sensitive_hidden_names_case_insensit
".NPMRC",
".PyPiRc",
".NETRC",
"id_rsa",
"test.pem",
]:
with pytest.raises(HTTPException) as exc_info:
normalize_uploaded_filename(raw_name)
Expand Down
Loading