fix: IDOR vulnerability on purchases endpoints (#294)#1675
Conversation
|
🎉 Welcome to Hybrid Recommender, @PrishaNagpal! This is your first contribution here! Labels added: PR Description Checklist: What happens next:
⏱️ Please respond to review comments within 48 hours. |
🎉 Welcome to Hybrid Recommender, @PrishaNagpal!Thank you for your first pull request! Here's what happens next:
⏱️ Please respond to any review comments within 48 hours. 📖 Resources: Happy contributing! 🚀 |
|
CI failures in celery_app.py and hybrid_model.py are pre-existing indentation bugs unrelated to this PR. My changes only affect backend/main.py purchases endpoints and tests/test_idor_purchases.py. |
|
PR #1633 ("fix: Duplicate results-processing loop removed from search_items(#1631)") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1640 ("fix: resolve hybrid_model merge conflicts and add explanation string") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1641 ("Fix/svd memory leak") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1642 ("Feature/evaluation dashboard") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1643 ("Feature/streamlit tfidf config") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1644 ("Fix/strict csrf origin validation") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1645 ("Feature/svd online updating") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1647 ("fix: add title query param endpoint to resolve HTTP 422 (#1075)") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1648 ("fix(federated): prevent regularization decay in aggregate_updates") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1650 ("fix: remove duplicate code block in hybrid_model.py causing Indentati…") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1653 ("fix: remove duplicate /api/recommend route") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1654 ("build: add faiss dependency for two-tower retrieval") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1655 ("fix: enforce stronger signup password validation") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1660 ("security: reject unissued csrf tokens") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1661 ("feat: add KNN-based user collaborative filtering (Issue #51)") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1665 ("fix: add missing faiss-cpu dependency to requirements.txt ") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1515 ("feat: harden realtime recommendation WebSocket flow") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
|
PR #1668 ("fix(ci): resolve syntax and indentation errors breaking upstream main") was just merged into Please rebase your branch to avoid conflicts: Keeping your branch up to date prevents merge conflicts. 🚀 |
What Changed
Added authentication and ownership checks to the purchases endpoints in
backend/main.py:GET /api/purchases/{user_id}— validates Bearer token (401) and checks JWT identity matches requesteduser_id(403)POST /api/purchases— validates Bearer token (401) and checks JWT identity matchesbody.user_id(403)tests/test_idor_purchases.pycovering auth, IDOR, input validation, boundary values, and happy pathWhy
The purchases endpoints trusted the
user_idsupplied in the request without verifying it against the authenticated user's token. An attacker logged in asuser-99could:GET /api/purchases/user-42with their own valid token and read another user's full purchase historyPOST /api/purchaseswithuser_id: user-42in the body and write purchase records into any user's accountCVSS score: High
How to Test
Expected result:
22 passed, 4 warningsScreenshots
N/A — No UI changes.
Checklist
flake8 .)Related Issue
Closes #294
AI Assistance Disclosure
_clear_response_cacheworkaround)