mirror of
https://github.com/atiilla/GeoIntel.git
synced 2026-04-26 16:15:57 +03:00
[PR #13] [MERGED] Security & code quality hardening: API key exposure, CORS, path traversal, temp file leak, input limits #13
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/GeoIntel#13
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/atiilla/GeoIntel/pull/13
Author: @Copilot
Created: 3/9/2026
Status: ✅ Merged
Merged: 3/9/2026
Merged by: @atiilla
Base:
main← Head:copilot/fix-security-issues📝 Commits (2)
4fb472aInitial plan8268e5csecurity: fix API key exposure, CORS, path traversal, temp file cleanup, input limits, debug mode, and unused imports📊 Changes
3 files changed (+57 additions, -37 deletions)
View changed files
📝
geointel/api_client.py(+4 -3)📝
geointel/image_processor.py(+1 -1)📝
geointel/web_server.py(+52 -33)📄 Description
Several security and code quality issues identified in code review — API key leaking via URL, overly permissive CORS, unguarded static file serving, temp file resource leak, unbounded prompt inputs, and minor code hygiene issues.
geointel/api_client.pyx-goog-api-keyheader — prevents key exposure in server logs, proxy logs, and browser historyraise APIError(...) from egeointel/web_server.pyCORS(app)→CORS(app, origins=["http://127.0.0.1:5000", "http://localhost:5000"])/<path:filename>route now rejects requests for extensions outsidehtml|css|js|ico|png|jpg|jpeg|svg|woff|woff2|ttf|maptry/finally; previously leaked on any exception between write and cleanupcontext_infoandlocation_guesstruncated to 500 chars (MAX_CONTEXT_LENGTH) before being forwarded to the AI prompt__main__block changed torun_server(debug=False)render_template,Optionalgeointel/image_processor.pyUnionOriginal prompt
Security & Code Quality Fixes
A code review identified the following issues that need to be addressed. Please fix all of them in a single PR.
🔴 Critical Security Issues
1. API Key in URL Query String —
geointel/api_client.pyline 39The Gemini API key is appended as a URL query parameter, which means it appears in server logs, browser history, and proxy logs.
Current:
Fix: Move the API key to the
x-goog-api-keyHTTP request header instead, and remove it from the URL:2. Overly Broad CORS Policy —
geointel/web_server.pyline 22CORS(app)with no arguments enables CORS for all origins.Fix: Restrict to localhost only since this is a local tool:
3. Path Traversal Risk via Catch-All Static File Route —
geointel/web_server.pylines 39–41The catch-all route
/<path:filename>could serve arbitrary files. Add an allowlist of safe extensions:🟡 Medium Issues
4. Temporary Files Not Cleaned Up on Error —
geointel/web_server.pyIf an exception occurs after saving the temp file but before the cleanup block, the file is never deleted.
Fix: Wrap the temp file lifecycle in a
try/finallyblock so cleanup always happens:5. No Input Length Limits on Prompt Fields —
geointel/web_server.pycontext_infoandlocation_guessare passed directly to the AI prompt with no length restriction.Fix: Add reasonable length caps:
6.
debug=Truein__main__block —geointel/web_server.pyline 240Running
web_server.pydirectly enables Flask's interactive debugger, which is dangerous.Fix:
7. Preserve Exception Chain —
geointel/api_client.pyline 200Use
raise ... from eto preserve the original exception chain for easier debugging:🟢 Minor / Code Quality Issues
8. Remove Unused Imports
geointel/web_server.pyline 6: Removerender_templateandOptional(unused)geointel/image_processor.pyline 4: RemoveUnion(unused)Summary of files to change:
geointel/api_client.py— Issues 1, 7geointel/web_server.py— Issues 2, 3, 4, 5, 6, 8geointel/image_processor.py— Issue 8Please make all these changes in a single pull request with a clear commit message.
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Code review
Assistant: Here is a thorough code review of the
atiilla/GeoIntelrepository. The project is well-structured overall, but there are several security, reliability, and code quality issues worth addressing.🔍 Code Review:
atiilla/GeoIntel🏗️ Architecture & Structure
The project is cleanly modularized:
api_client.py— Gemini API communicationimage_processor.py— Image loading, validation, encodinggeointel.py— Core orchestrationweb_server.py— Flask web APIcli.py— CLI interfaceconfig.py— Central configurationgeointel_ui_template/— Frontend (HTML + JS)This separation of concerns is a strength. ✅
🔴 Critical Issues
1. API Key Transmitted in URL Query String
File:
geointel/api_client.py, line 39