Skip to content

Fix BOLA: GET /books/v1/{book_title} leaks any user's secret_content - #69

Closed
beanbeah wants to merge 1 commit into
OWASP-CTF:dc34-ctffrom
beanbeah:ctf/challenge-3-bola-book-secrets
Closed

beanbeah wants to merge 1 commit into
OWASP-CTF:dc34-ctffrom
beanbeah:ctf/challenge-3-bola-book-secrets

Conversation

@beanbeah

@beanbeah beanbeah commented Aug 9, 2026

Copy link
Copy Markdown

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 its secret_content to 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.py get_by_title() now resolves the requesting user from the validated token's subject and requires the candidate book's user_id to match the requester's id before 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):

  • Seeded DB via /createdb (name1/pass1 owns bookTitle3, name2/pass2 owns bookTitle18, admin owns bookTitle91).
  • Logged in as name1, then:
    • GET /books/v1/bookTitle3 (own book) → 200 with secret ✔ legitimate access still works
    • GET /books/v1/bookTitle18 (name2's book) → 404 Book not found ✔ exploit blocked
    • GET /books/v1/bookTitle91 (admin's book) → 404 Book not found ✔ exploit blocked

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.
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

🏆 VAmPI — CTF Patch Score

███░░░░░░░░░░░░░░░░░  2 / 16 pts  (13%)

1 / 9 challenges patched

Per-challenge detail is withheld — it would reveal the rubric.

Commit: c729b49 · scoring run

🎉 Your result is on the leaderboard — see where you rank! 🏆

@beanbeah

beanbeah commented Aug 9, 2026

Copy link
Copy Markdown
Author

Superseded by consolidated PR #74 (#74), which merges all validated challenge fixes into one branch. Closing this individual PR.

@beanbeah beanbeah closed this Aug 9, 2026
@beanbeah
beanbeah deleted the ctf/challenge-3-bola-book-secrets branch August 9, 2026 13:57
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