fix(#98): verify ownership before deleting a resource#104
Merged
durdana3105 merged 1 commit intoMay 26, 2026
Merged
Conversation
deleteResource previously accepted a resourceId and fileUrl from the caller and acted on both without any authorization check. An attacker could pass a victim's resourceId alongside their own fileUrl, causing the storage delete to succeed (their file) while the DB delete failed (victim's row protected by RLS), leaving the victim's row pointing at a permanently missing file. Fix: - Look up the resource by id AND uploaded_by = auth.uid() before touching anything. Return a 'not found or unauthorized' error if the row is not owned by the caller. - Derive file_url from the DB row instead of trusting caller input, eliminating the cross-user storage/DB mismatch vector. - Remove the fileUrl parameter from the function signature; update the only caller (ResourceCard.tsx) accordingly.
|
@anshul23102 is attempting to deploy a commit to the durdana3105's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Closes #98
Problem
deleteResourceaccepted aresourceIdandfileUrlfrom the caller and acted on both without verifying the caller owns the resource. An attacker knowing a victim's resource DB row ID could calldeleteResource(victimId, attackerFilePath):Changes
src/lib/deleteResource.tssupabase.auth.getUser()before any mutation.eq("id", resourceId)and.eq("uploaded_by", user.id)- returns an error if the row is not found or not owned by the callerfile_urlfrom the fetched DB row rather than the caller-supplied argument, eliminating the cross-user storage/DB mismatch vectorfileUrlfrom the function signature (it is now derived from the DB)src/components/resources/ResourceCard.tsxdeleteResourcecall to pass onlyresource.id(nofile_urlargument)Before / After