fix(security): resolve 50 CodeQL stack-trace-exposure alerts across API routers - #27
Merged
Merged
Conversation
added 3 commits
September 27, 2026 05:43
…k hashing alerts - py/full-ssrf (#42): validate URL scheme, block restricted metadata hosts, and reconstruct safe endpoints with urlunsplit in litellm_service and settings router - py/polynomial-redos (#43, #44): optimize template literal regex and switch Next.js route path extraction to deterministic component splitting in api_route_extractor - js/incomplete-url-substring-sanitization (#95): parse hostname via new URL and verify domain boundaries in SearchInspector.tsx - py/clear-text-logging-sensitive-data (#1, #2, #3): sanitize logging in key_service by eliminating key prefix strings from log messages - py/weak-sensitive-data-hashing (#41): use PBKDF2-HMAC-SHA256 with salt for API key hashing in key_service - sync test counts in REQUIREMENTS.md
- local_storage.py: enforce explicit storage_root startswith and commonpath containment in resolve_safe_path, save_file_content, index_file, read_file_content, delete_file, and get_file_tree - file_reader.py: add root_prefix startswith validation in _is_within_root for both target and symlink paths - summarizer.py: normalize filepath and enforce storage prefix containment when reading from disk/storage - repositories.py: sanitize and validate paths against null bytes and .. traversal in api_add_path and api_browse_dir - files.py: validate input path against traversal in api_summarize_file - indexing/processor.py: normalize filepath before checking existence and mtime - vector_store (chroma & qdrant): normalize target_storage path before directory creation and client initialization - pdf_extractor.py: normalize source path before checking existence, size, and opening document - adr.py: normalize filepath before checking existence and reading ADR markdown content
…PI routers - Sanitize exception responses across endpoints in settings.py, storage.py, repositories.py, navigator.py, graph.py, ingestion.py, and webhooks.py. - Ensure internal exception objects and stack traces are logged server-side rather than leaked to clients. - Update test error handling assertions to verify 500 status and error presence without relying on exposed internal exception messages.
| if content is None: | ||
| if os.path.exists(filepath): | ||
| norm_fp = os.path.normpath(os.path.abspath(filepath)) | ||
| if os.path.exists(norm_fp) and os.path.isfile(norm_fp): |
| if content is None: | ||
| if os.path.exists(filepath): | ||
| norm_fp = os.path.normpath(os.path.abspath(filepath)) | ||
| if os.path.exists(norm_fp) and os.path.isfile(norm_fp): |
| if os.path.exists(norm_fp) and os.path.isfile(norm_fp): | ||
| try: | ||
| with open(filepath, "r", encoding="utf-8", errors="replace") as f: | ||
| with open(norm_fp, "r", encoding="utf-8", errors="replace") as f: |
| os.makedirs(target_storage, exist_ok=True) | ||
| self.client = chromadb.PersistentClient(path=target_storage) | ||
| clean_storage = os.path.normpath(os.path.abspath(target_storage)) | ||
| os.makedirs(clean_storage, exist_ok=True) |
| os.makedirs(target_storage, exist_ok=True) | ||
| self.client = chromadb.PersistentClient(path=target_storage) | ||
| clean_storage = os.path.normpath(os.path.abspath(target_storage)) | ||
| os.makedirs(clean_storage, exist_ok=True) |
| os.makedirs(target_storage, exist_ok=True) | ||
| self.client = QdrantClient(path=target_storage) | ||
| clean_storage = os.path.normpath(os.path.abspath(target_storage)) | ||
| os.makedirs(clean_storage, exist_ok=True) |
| os.makedirs(target_storage, exist_ok=True) | ||
| self.client = QdrantClient(path=target_storage) | ||
| clean_storage = os.path.normpath(os.path.abspath(target_storage)) | ||
| os.makedirs(clean_storage, exist_ok=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves 50 CodeQL
py/stack-trace-exposuresecurity alerts across ContextCortex backend API router endpoints:app/api/routers/settings.py: Sanitized 21 alerts across endpoints fetching stats, managing Git host credentials, updating tokens, configuring auto-sync, retrieving/clearing diagnostic logs, testing/switching vector stores, discovering models, and updating embedding/file configurations.app/api/routers/storage.py: Sanitized 12 alerts across PDF preview, file upload, file replace, file retrieval, file deletion, and storage file tree endpoints.app/api/routers/repositories.py: Sanitized 10 alerts across repository sync, repo creation, repo deletion, auto-sync toggle, branch discovery, and file browsing endpoints.app/api/routers/navigator.py: Sanitized 3 alerts across symbols lookup, file references, and codebase search endpoints.app/api/routers/graph.py: Sanitized 2 alerts across topology and dependencies graph endpoints.app/api/routers/ingestion.py: Sanitized 1 alert across ingestion status endpoint.app/api/webhooks.py: Sanitized 1 alert on invalid webhook JSON payloads.All internal exception details and stack traces are logged server-side via
logger.errororlogger.warningrather than returned to API clients.Verification