Commit Graph

56 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] 3035802c16 feat(security): add comprehensive input validation and sanitization (#172)
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 16:02:00 +00:00
github-actions[bot] 77e777418c style: apply ruff auto-fix
- Auto-formatted code with ruff format
- Applied ruff linting fixes with --fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-22 15:25:48 +00:00
copilot-swe-agent[bot] ca27a0b687 feat(security): add request size limits to API endpoints
- Add RequestSizeLimitMiddleware that checks Content-Length header
  before request body is read: non-multipart requests capped at
  MAX_REQUEST_BODY_SIZE (default 1 MB), multipart uploads capped at
  MAX_UPLOAD_SIZE (default 1 GB). Returns HTTP 413 on violation.
- Register middleware in app/main.py
- Add max_request_body_size setting to app/config.py
- Fix ui_upload in files.py to check Content-Length early and read
  in 64 KB chunks (bounded memory usage), removing the post-write
  os.path.getsize check
- Document MAX_REQUEST_BODY_SIZE in .env.demo and ConfigurationGuide.md
- Mark SECURITY_AUDIT.md item #4 as resolved
- Add 9 tests in test_request_size_limit.py
- Update test_upload_file_too_large to use patch.object instead of
  the now-unused os.path.getsize mock

Closes #173

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-22 14:41:04 +00:00
copilot-swe-agent[bot] f2eff3e2fb fix: return boolean values from _should_upload functions and fix test expectations
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-16 16:59:17 +00:00
copilot-swe-agent[bot] e6a4995a5c style: run ruff format on 6 files to fix formatting issues
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 22:39:34 +00:00
copilot-swe-agent[bot] c129badc14 feat(api): add enhanced logging and original_file_path fallback to retry-subtask endpoint
- Add comprehensive logging to all pipeline retry branches (process_document, process_with_azure_document_intelligence, extract_metadata_with_gpt, embed_metadata_into_pdf)
- Add original_file_path as 3rd fallback for embed_metadata_into_pdf (checks: local_filename, processed_file_path, original_file_path, workdir/tmp fallback)
- Include all checked paths with existence status in 400 error responses for easier debugging
- Add enhanced logging to upload task retry path showing which processed file paths were checked
- Log successful file path when found
- Add comprehensive test suite covering new logging and fallback behavior

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 22:15:18 +00:00
copilot-swe-agent[bot] bcf5f652fc style: fix linting issues in retry and metadata extraction code
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 21:07:23 +00:00
copilot-swe-agent[bot] 42d35c7c6f fix: handle file in processed directory when retrying embed_metadata_into_pdf
- Update _retry_pipeline_step to check for file in tmp, processed, and fallback locations
- Pass full path to extract_metadata_with_gpt instead of just basename
- Update extract_metadata_with_gpt to handle both basename and full path parameters
- Add test case for retrying when file is in processed directory

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 21:06:20 +00:00
copilot-swe-agent[bot] b42c6f5f64 fix: resolve all Ruff linting errors
- Fix PLW2901: Use different variable name for stripped lines in loop
- Fix E721: Use 'is' instead of '==' for type comparisons
- Add noqa comments for intentional security warnings (S321, S507, S110, S603)

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 16:12:39 +00:00
copilot-swe-agent[bot] 4897cb6655 fix: apply Phase 1-2 correctness and constant extraction from PR #273
- Replace datetime.utcnow() with datetime.now(timezone.utc) in 4 files
- Extract duplicate literals to constants in 5 files
  - models.py: "files.id" → _FILES_ID_FK
  - upload_to_email.py: "logo.png" → _LOGO_FILENAME
  - general.py: "%B %d, %Y" → _DATE_DISPLAY_FORMAT
  - files.py: "File not found" → _FILE_NOT_FOUND
  - upload_to_google_drive.py: Google token URL → _GOOGLE_TOKEN_URL

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 11:25:30 +00:00
copilot-swe-agent[bot] 43bc58770d refactor: consolidate linting tools into Ruff
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-13 09:10:52 +00:00
copilot-swe-agent[bot] dff32e08e1 test: add comprehensive tests for critical untested files and fix deprecated warnings
- Add tests for migrate_logs_to_steps.py, upload_to_paperless.py, dropbox API,
  upload_to_dropbox.py, upload_to_nextcloud.py, upload_to_onedrive.py,
  upload_with_rclone.py, and config_validator.py
- Fix PydanticDeprecatedSince20: @validator → @field_validator in config.py, url_upload.py
- Fix PydanticDeprecatedSince20: class Config → model_config = SettingsConfigDict
- Fix PydanticDeprecatedSince211: filter Pydantic internals in settings_display.py
- Fix MovedIn20Warning: use sqlalchemy.orm.declarative_base instead of ext.declarative

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-12 17:32:17 +00:00
copilot-swe-agent[bot] ff9a3ff49f style: fix code formatting with black, isort, and flake8
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-12 03:21:41 +00:00
copilot-swe-agent[bot] cc98039246 fix(deps): upgrade PyPDF2 to pypdf >= 3.9.0 to fix CVE-2023-36464
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-12 02:52:17 +00:00
copilot-swe-agent[bot] 73a0222e56 feat(storage): implement immutable original/processed file storage and collision handling
- Add original_file_path and processed_file_path columns to FileRecord model
- Create database migration for new fields
- Implement get_unique_filepath_with_counter() with -0001 suffix format
- Update process_document to save immutable copy to /workdir/original
- Add force_cloud_ocr parameter to process_document for forced OCR
- Update embed_metadata to use new collision handling
- Update metadata JSON to include file path references
- Add /files/{file_id}/reprocess-with-cloud-ocr API endpoint
- Update processed_file_path in database during embedding

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-11 20:10:19 +00:00
copilot-swe-agent[bot] 5e82f7c03a refactor: fix static method warnings, hard-coded credentials, and Annotated type hints
- Add @staticmethod to 9 test methods in test_external_integrations.py
  that don't use self (PYL-R0201)
- Extract hard-coded password literals to constants in 6 test files
  to resolve S2068 warnings (fixtures_integration, test_imap_tasks,
  test_upload_tasks, test_upload_webdav_comprehensive,
  test_upload_webdav_integration, test_views_coverage)
- Migrate Form() dependency injection to Annotated type hints in
  dropbox.py, google_drive.py, onedrive.py (Sonar fastapi convention)

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-11 17:03:54 +00:00
copilot-swe-agent[bot] 3a40fe59f5 refactor(api): migrate Depends() to Annotated type hint style in app/api/
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-11 16:54:55 +00:00
copilot-swe-agent[bot] 9cd7a80cbc fix(api): add Request parameter to process_url endpoint for session access
The @require_login decorator expects a Starlette Request as the first
parameter to access request.session, but process_url only had a
URLUploadRequest Pydantic model parameter. This caused an
AttributeError: 'URLUploadRequest' object has no attribute 'session'
when POST /api/process-url was called.

Fix: Add `request: Request` as the first parameter and rename the
Pydantic model parameter from `request` to `url_request`.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-11 14:25:57 +00:00
copilot-swe-agent[bot] 47a1de953d refactor: address code review comments
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-11 13:39:35 +00:00
copilot-swe-agent[bot] 245e298991 feat: add URL-based file upload with SSRF protection
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-11 13:36:23 +00:00
copilot-swe-agent[bot] f7799e409d fix(tasks): prevent filename overwrite in extract_metadata_with_gpt and fix embed retry logic
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-11 08:59:27 +00:00
copilot-swe-agent[bot] afb4d9bf85 refactor(api): address code review feedback - extract PDF text helper, improve comments
- Extract duplicated PDF text extraction into _extract_text_from_pdf helper
- Clarify empty metadata dict comment for embed_metadata_into_pdf retry
- Make test assertion for file_id passing more explicit

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-10 21:11:46 +00:00
copilot-swe-agent[bot] 11c7d15a90 fix(tasks): skip duplicate check when reprocessing and enable retry from failed pipeline step
- Add file_id parameter to process_document to skip duplicate hash check on reprocess
- Pass file_id from reprocess_single_file and bulk_reprocess_files endpoints
- Extend retry-subtask endpoint to support pipeline steps (process_document,
  process_with_azure_document_intelligence, extract_metadata_with_gpt,
  embed_metadata_into_pdf) in addition to upload tasks
- Add retry button for failed main pipeline steps in file detail UI
- Add comprehensive tests for reprocessing and pipeline step retry

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-10 21:09:53 +00:00
copilot-swe-agent[bot] 8edc11da04 refactor: extract shared file-status query logic into utility function
- Created app/utils/file_queries.py with apply_status_filter function
- Updated app/api/files.py to use shared function
- Updated app/views/files.py to use shared function
- Removed unused 'or_' import from app/api/files.py
- Added comprehensive tests in tests/test_file_queries.py
- All tests pass (10 new tests, 14 existing tests verified)

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-10 20:40:11 +00:00
copilot-swe-agent[bot] 8d347e0a53 feat: Add rate limiting middleware with SlowAPI
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-10 16:17:53 +00:00
copilot-swe-agent[bot] 9ad32e40e6 feat(security): add configurable file upload size limits with optional splitting
- Add MAX_UPLOAD_SIZE config (default 1GB) to prevent resource exhaustion
- Add MAX_SINGLE_FILE_SIZE config for optional PDF file splitting
- Implement automatic PDF splitting when files exceed single file limit
- Update upload endpoint to use configured limits instead of hardcoded 500MB
- Add comprehensive tests for upload limits and file splitting
- Document configuration in ConfigurationGuide.md and SECURITY_AUDIT.md
- Reference SECURITY_AUDIT.md in error messages for user guidance

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-10 10:51:30 +00:00
copilot-swe-agent[bot] 2bcd774d6d fix(security): enhance path traversal protection in file uploads
- Import and use sanitize_filename utility in ui_upload endpoint
- Enhance sanitize_filename to handle Windows-style paths (backslashes)
- Add protection against path traversal patterns (..)
- Replace all path separators with underscores
- Add comprehensive security tests for Windows-style paths and mixed separators
- All existing tests pass with improved security

This addresses the "Uncontrolled data used in path expression" code scanning alert
by ensuring all user-provided filenames are properly sanitized before being used
in any file operations or stored in the database.

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-09 21:00:51 +00:00
copilot-swe-agent[bot] 98cf9e0e0b refactor: consolidate get_db into single module
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-09 15:37:23 +00:00
copilot-swe-agent[bot] d08040ac4a style: fix all flake8 linter errors across app/ directory
- Run Black formatter and isort on all app/ files
- Remove unused imports (F401) across multiple files
- Add # noqa: F401 for intentional re-exports in celery_worker.py,
  tasks/__init__.py, utils.py, frontend.py, views/base.py
- Fix f-strings without placeholders (F541) in azure.py, notification.py,
  check_credentials.py, upload_to_onedrive.py, settings.py
- Fix bare except (E722) in upload_to_sftp.py
- Fix block comment format (E265) in models.py
- Move imports to top of file to fix E402 in celery_app.py, celery_worker.py
- Fix line-too-long (E501) by wrapping strings in multiple files
- Remove unused variable (F841) in upload_to_nextcloud.py

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-08 17:42:33 +00:00
copilot-swe-agent[bot] 334714423e fix(ui): address code review feedback on inline preview
- Remove invalid type attribute from iframe elements
- Add dedicated download endpoint with attachment disposition
- Update download links to use new endpoint instead of preview

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-08 16:16:31 +00:00
copilot-swe-agent[bot] ed0bac7345 feat(ui): add auto-refresh after upload and inline file preview
- Auto-refresh files table after successful uploads using custom event
- Add inline preview support for PDFs, images, and text files
- Set Content-Disposition header to inline for preview endpoint
- Add download button as secondary action in file details view

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-08 16:12:44 +00:00
copilot-swe-agent[bot] b97c80d6bd fix: address code review feedback on security and type hints
- Use Optional[int] type hint for timeout parameter in oauth_helper
- Replace bare Exception with specific ValueError and JSONDecodeError
- Strengthen rclone remote name validation (must start with alphanumeric)
- Fix path traversal validation to check against workdir for absolute paths
- Add comprehensive comments for security validations

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-08 08:31:21 +00:00
copilot-swe-agent[bot] d2eb9846d3 style: fix linting issues and remove unused imports
- Remove unused imports from all modified files
- Fix flake8 violations (unused variables, f-strings without placeholders)
- Apply Black formatting consistently
- Shorten long line in google_drive.py

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-08 08:29:38 +00:00
copilot-swe-agent[bot] 551b23a80c fix(security): reduce code duplication and fix security issues in OAuth and file handling
- Extract common OAuth token exchange logic to shared utility (oauth_helper.py)
- Remove sensitive data logging (client_secret, authorization codes)
- Add path traversal validation in resolve_file_path()
- Add input validation for rclone destination parameter
- Replace bare Exception catches with specific exception types
- Use RuntimeError instead of generic Exception for better error handling

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-08 08:26:10 +00:00
copilot-swe-agent[bot] 78004cd9a4 style: Apply Black formatting to modified files
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-08 08:16:54 +00:00
copilot-swe-agent[bot] 0a461343e7 fix: Add service containers and fix test failures
- Add Redis and RabbitMQ services to CI workflow
- Fix Jinja2 template error by passing file=None in error cases
- Fix test expecting dict response format for list_files endpoint
- Fix NOT NULL constraint by providing valid local_filename
- Fix retry-subtask to validate subtask name before checking processed file
- Add mock for process_document in reprocess test

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-08 08:14:09 +00:00
copilot-swe-agent[bot] c9e1de4845 Fix /settings redirect issue and add OAuth admin support
- Convert require_admin_access to proper decorator pattern
- Fix redirect loop that was sending all users to /
- Add is_admin flag handling for OAuth users (checks groups)
- Update SETTING_METADATA with all 102 settings from config.py
- Improve API admin check with type hints

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-08 06:02:21 +00:00
copilot-swe-agent[bot] 54e93dcdf2 Fix settings API route prefix to avoid double /api/ in URL
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 22:36:32 +00:00
copilot-swe-agent[bot] e1bb9de915 Add settings management infrastructure: models, API, views, and database loading
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 22:31:06 +00:00
copilot-swe-agent[bot] 910fe86603 Add branching visualization, per-subtask retry, and step summary to file detail view
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 22:08:09 +00:00
copilot-swe-agent[bot] 76ab698105 Add backend endpoints and enhanced file detail view
- Added /api/files/{file_id}/reprocess endpoint for single file reprocessing
- Added /api/files/{file_id}/preview endpoint for viewing original/processed files
- Enhanced file detail view with process flow computation
- Updated frontend template with retry button, process flow visualization, and PDF previews
- Added JavaScript for async retry functionality

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 20:52:08 +00:00
copilot-swe-agent[bot] edd1acb3a1 Fix all high and medium severity security issues found by Bandit
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 19:35:40 +00:00
copilot-swe-agent[bot] 7d24b7c668 Apply code formatting and fix linting issues
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 17:37:50 +00:00
copilot-swe-agent[bot] 2db58afedf Add original_filename parameter to preserve user's filename
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 17:36:36 +00:00
copilot-swe-agent[bot] 08775459aa Fix /files view issues and add bulk operations
- Fixed status filter in /files view endpoint
- Added bulk delete and reprocess API endpoints
- Added bulk selection UI with checkboxes
- Added bulk actions bar with reprocess and delete buttons
- Updated JavaScript to handle bulk operations

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 15:52:38 +00:00
copilot-swe-agent[bot] 775ffa5082 Address code review feedback
- Fixed status filtering to occur before pagination for correct counts
- Resolved N+1 query problem by batch-fetching processing statuses
- Extracted status computation logic to shared utility function
- Changed sort indicator from ⬍ to ↕ for better browser compatibility
- Updated both API and view layers to use shared status utilities

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 15:20:59 +00:00
copilot-swe-agent[bot] 530c63ad14 Add server-side pagination, filtering, sorting, and file detail view
- Updated /api/files endpoint with pagination, filtering, and sorting support
- Added /api/files/{file_id} endpoint for detailed file information
- Updated /files view to support server-side operations
- Added /files/{file_id}/detail route for file detail page
- Created new files.html with filters, status column, and pagination
- Created file_detail.html for viewing processing history
- Status computed from ProcessingLog entries (pending, processing, completed, failed)

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 15:12:49 +00:00
copilot-swe-agent[bot] a12ccdabac Apply Black and isort formatting to modified files
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 15:00:18 +00:00
copilot-swe-agent[bot] 8eea420bc5 Add throttling to /processall endpoint to prevent overwhelming downstream APIs
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-07 14:59:19 +00:00
copilot-swe-agent[bot] 1903dc5bcd Add comprehensive processing logging system
- Added database logging to all major processing tasks
- Created API endpoints for retrieving processing logs
- Updated frontend to display processing logs per file
- Logging includes: process_document, convert_to_pdf, extract_metadata_with_gpt, embed_metadata_into_pdf, finalize_document_storage, send_to_all_destinations

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
2026-02-06 22:30:18 +00:00