Skip to content

fix: validate uploaded photo objects - #26

Merged
g4st3r-d3v merged 1 commit into
masterfrom
feature/photo-upload-hardening
May 17, 2026
Merged

g4st3r-d3v merged 1 commit into
masterfrom
feature/photo-upload-hardening

Conversation

@g4st3r-d3v

Copy link
Copy Markdown
Contributor

Summary

  • Added S3 head_object validation before confirming uploaded photos for user avatars, tutor profile photos, and tutor service photos.
  • Rejects missing objects, empty objects, objects over PHOTO_MAX_BYTES (8 MB), unavailable size/content type, and S3 content-type mismatches.
  • Persists trusted S3 ContentLength / normalized ContentType instead of client-provided size/type on confirm.
  • Documented staging S3 CORS requirements for future PWA presigned PUT/GET uploads.

E2E Trace

  • Upload URL endpoints already generated storage keys and 900 second presigned PUT URLs.
  • Gap found: confirm endpoints accepted storage_key, content_type, and size_bytes without verifying that the object existed in S3 or matched metadata.
  • This PR closes that gap by requiring a successful S3 HEAD during confirm for all three photo types before DB rows are written.
  • Rendering path remains compatible with existing private bucket behavior: persisted objects are still served through proxy/presigned GET depending on MEDIA_READ_VIA_PROXY.

Checks

  • uvx black app/services/media_uploads.py tests/tutor_profile_photos/test_create_photo.py && uvx isort app/services/media_uploads.py tests/tutor_profile_photos/test_create_photo.py passed.
  • DEBUG=true ENVIRONMENT=local DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/app_db uv run --group dev python -m compileall app tests passed.
  • Targeted pytest attempted: DEBUG=true ENVIRONMENT=local DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/app_db uv run --group dev pytest tests/tutor_profile_photos/test_create_photo.py tests/user_avatars/test_user_avatars.py tests/tutor_service_photos/test_tutor_service_photos.py; blocked at fixture setup because local Postgres on localhost:5432 refused connections. Docker/Colima was also unavailable locally.

Companion

@g4st3r-d3v
g4st3r-d3v marked this pull request as ready for review May 17, 2026 10:22
@g4st3r-d3v
g4st3r-d3v merged commit 0c43236 into master May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant