Conversation
The book-lookup endpoint returned any book's secret_content to any authenticated caller, keyed only on book_title with no ownership check against the requester. Enforce object-level authorization unconditionally: resolve the requesting user from the validated token's subject, look up the candidate book, and require the book's user_id to match the requester's id before returning its secret. Non-owned or non-existent titles both return a generic 404 so the endpoint doesn't leak which titles exist. Verified locally: logging in as name1 and requesting name2's and admin's books now returns 404 Book not found, while name1's own book still returns 200 with its secret.
🏆 VAmPI — CTF Patch Score1 / 9 challenges patched
Commit: 🎉 Your result is on the leaderboard — see where you rank! 🏆 |
Author
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.
Vulnerability: API1:2019 Broken Object Level Authorization
GET /books/v1/{book_title}looked up the book purely by title (Book.query.filter_by(book_title=...)) and returned itssecret_contentto any authenticated caller, with no check that the caller actually owns that book. Any logged-in user could read any other user's (including admin's) book secrets simply by guessing/enumerating titles.Fix:
api_views/books.pyget_by_title()now resolves the requesting user from the validated token's subject and requires the candidate book'suser_idto match the requester'sidbefore returning the secret. Non-owned and non-existent titles both return a generic 404, so the endpoint no longer distinguishes 'exists but not yours' from 'doesn't exist'.Local verification (WSL, vulnerable=1):
/createdb(name1/pass1 ownsbookTitle3, name2/pass2 ownsbookTitle18, admin ownsbookTitle91).name1, then:GET /books/v1/bookTitle3(own book) → 200 with secret ✔ legitimate access still worksGET /books/v1/bookTitle18(name2's book) → 404 Book not found ✔ exploit blockedGET /books/v1/bookTitle91(admin's book) → 404 Book not found ✔ exploit blocked