Fix code review issues: security, race conditions, resource leaks

- Fix race condition: pass return_timestamps as parameter instead of mutating shared state
- Remove /local/transcriptions endpoint (path traversal vulnerability)
- Add timeout=30 and URL scheme validation to prevent SSRF
- Add temp file cleanup via try/finally in all route handlers
- AsyncTaskManager: add threading.Lock and TTL cleanup for completed tasks
- Change audio_rate to 16000 (matches Whisper's expected sample rate)
- Extract filename from URL via Content-Disposition/path
- Detect base64 audio format via python-magic
- Fix response_size_bytes to use json.dumps instead of str()
- Move scipy import to module level
- Clamp temperature to [0.0, 1.0]
- Deduplicate _load_model() code
- Fix docstrings, README structure, typo, log level

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serge Zaigraeff
2026-03-30 00:54:50 +03:00
co-authored by Claude Opus 4.6
parent ff4bd2ba3d
commit 2138651474
12 changed files with 153 additions and 189 deletions
+14 -7
View File
@@ -224,13 +224,20 @@ The project consists of the following components:
- `config.json`: Service configuration file
- `app/`: Main application module
- `__init__.py`: Contains the `WhisperServiceAPI` class for service initialization
- `utils.py`: Logging configuration
- `transcriber.py`: Contains the `WhisperTranscriber` class for speech recognition
- `audio_processor.py`: Contains the `AudioProcessor` class for audio preprocessing
- `audio_sources.py`: Contains different audio source handlers (upload, URL, base64, local)
- `transcriber_service.py`: Manages the transcription workflow
- `history_logger.py`: Handles saving transcription history
- `routes.py`: Contains the API route definitions
- `routes.py`: API route definitions
- `history.py`: Saving transcription history
- `core/`: Core logic
- `transcriber.py`: `WhisperTranscriber` class for speech recognition
- `transcription_service.py`: Manages the transcription workflow
- `audio/`: Audio processing
- `processor.py`: `AudioProcessor` class for audio preprocessing
- `sources.py`: Audio source handlers (upload, URL, base64)
- `utils.py`: Audio utilities (loading, duration)
- `infrastructure/`: Supporting modules
- `log.py`: Logging configuration
- `validation.py`: File validation
- `storage.py`: Temp file management
- `async_tasks.py`: Async task manager
- `static/`: Web interface files
## Advanced usage