Repository navigation
security: presigned URLs in UploadDto, honour the anon flag (BREAKING) - #9
Open
IbraTech04 wants to merge 1 commit into
Open
IbraTech04 wants to merge 1 commit into
IbraTech04 wants to merge 1 commit into
Conversation
UploadDto.fileUrl was the verbatim R2 object key. Verified live as an
ordinary ROLE_USER, GET /api/user/uploads returned:
{"fileUrl":"images/e5c6f37c-...","uploadedBy":"f7b1d402-...",
"approved":true,"anon":true}
Two defects in one response. The bucket is fronted by a public custom
domain (PosterService serves publicUrl + "/" + objectKey unsigned), so
a leaked key is a direct unauthenticated fetch of the media -- and
AdminUploadDto deliberately routes through R2StorageService.getSecureUrl,
which throws SecurityException for unapproved content. The user-facing
path skipped that boundary entirely. Separately, uploadedBy was
serialized even when anon=true, revoking the anonymity the uploader was
promised at submit time.
fileUrl and thumbnailUrl are now absolute expiring presigned URLs
issued through the approval gate, with urlExpiresAt so clients re-fetch
rather than cache. uploadedBy and instagramHandle are null on anonymous
uploads unless the caller is the uploader or holds media:upload:read.
Breaking change for utmmsa-pwa; see CLIENT_MIGRATION.md.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011xQusSt39vP3c82gAUXRCm
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Collaborator
Author
|
This PR clobbers #8 and a lot of what they fix is sort of the same. It should be folded into that PR is cleaned up. |
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.
The problem
Verified live on
localhost:8080as an ordinaryROLE_USER,GET /api/user/uploadsreturned:{"uuid":"dbc118c8-…","fileUrl":"images/e5c6f37c-845d-4252-9a2f-16e5e68eee96", "thumbnailUrl":"thumbnails/e5c6f37c-…","uploadedBy":"f7b1d402-14bb-4c60-b7bb-d7bf54dc5d00", "approved":true,"anon":true}Two defects in a single response.
1. The raw R2 object key is handed to the client.
AdminUploadDtodeliberately routes throughR2StorageService.getSecureUrl(key, approved, isAdmin), which throwsSecurityExceptionwhen the content is not approved and the caller is not an admin. The user-facingUploadDtopath skipped that security boundary entirely and returned the key verbatim.PosterService.java:100,181servespublicUrl + "/" + objectKeyunsigned, which confirms the bucket sits behind a public custom domain (media.lensbridge.tech) — so a leaked key is a direct, unauthenticated fetch of the media, bypassing the approval gate.2.
uploadedByis serialized onanon: trueuploads. The uploader was promised anonymity at submit time; shipping the author id revokes it. Note the upload above is flaggedanon:trueand still carries the uploader UUID.The fix
fileUrlandthumbnailUrlare now absolute, expiring presigned URLs produced bygetSecureUrl, so the approval gate is enforced at the point the URL is minted. Both arenullwhen the caller may not see the bytes.urlExpiresAttells clients when to re-fetch instead of caching a URL that will start 403ing.uploadedByandinstagramHandlearenullon anonymous uploads unless the caller is the uploader or holdsmedia:upload:read.@Schemaannotations carry the same warning into the generated OpenAPI spec.fileUrlis no longer a key to concatenate onto a media base URL — it is the complete URL. SeeCLIENT_MIGRATION.mdin this PR for exactly whatutmmsa-pwamust change. The frontend repo is untouched here.Verification
URL shape (absolute, signed, expiring) is asserted against a mocked S3 presigner rather than a live R2 call, since this machine has no reachable bucket.
Merge note
Touches
UploadService.java, which the sibling upload-IDOR PR also edits. Expect a small conflict depending on merge order — the changes are independent (this one is DTO field mapping, that one is authorization filtering).🤖 Generated with Claude Code
https://claude.ai/code/session_011xQusSt39vP3c82gAUXRCm