Skip to content

fix(quiz): scope graph_nodes by user_id in generate/submit (IDOR)#204

Merged
Jose-Gael-Cruz-Lopez merged 2 commits into
mainfrom
fix/quiz-node-ownership
Jun 12, 2026
Merged

fix(quiz): scope graph_nodes by user_id in generate/submit (IDOR)#204
Jose-Gael-Cruz-Lopez merged 2 commits into
mainfrom
fix/quiz-node-ownership

Conversation

@Jose-Gael-Cruz-Lopez

Copy link
Copy Markdown
Member

What

Scope every graph_nodes access in the quiz flow by the owning user so a caller can only generate/submit quizzes against their own concept nodes. Foreign or missing nodes now return 404 instead of leaking content or corrupting another user's mastery.

  • generate_quiz and _legacy_generate_quiz: node read filtered by {id, user_id: body.user_id}.
  • submit_quiz: the mastery read/write and the concept_name read are filtered by {id, user_id: attempt["user_id"]}; a missing/foreign node now raises 404 before any mastery write (previously it silently defaulted mastery_before=0.0 and wrote to graph_nodes WHERE id=<victim node>).

Why

require_self(body.user_id) only checks that the request body's user_id equals the session user — it never verifies the targeted node belongs to that user. Every graph_nodes read/write in the quiz flow filtered by id alone (unlike services/graph_service.py, which scopes by user_id). An authenticated attacker could:

  1. POST /api/quiz/generate with their own user_id + a victim's concept_node_id → 200 + a quiz_attempts row they own (and the victim's concept content leaks into the generated quiz).
  2. POST /api/quiz/submit for that attempt → require_self(attempt["user_id"]) passes, and the handler overwrites the victim's mastery_score, mastery_tier, times_studied, last_studied_at, and mastery_events.

High-severity IDOR / cross-user data-integrity bug.

How verified

  • cd backend && PYTHONPATH=. python -m pytest tests/test_quiz_routes.py -q32 passed (30 pre-existing + 2 new).
  • New TestQuizNodeOwnership proves user A cannot generate or submit against user B's node (both 404) and that submit writes nothing to graph_nodes. The mock models real DB row-filtering, so both tests fail on the unscoped code and pass only with the fix (verified by stashing the route change).

Closes #157

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Jose-Gael-Cruz-Lopez, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 minutes and 49 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 11f2e8dd-cebb-4970-86ca-036a5d7153ff

📥 Commits

Reviewing files that changed from the base of the PR and between 5edadd0 and 38a0399.

📒 Files selected for processing (2)
  • backend/routes/quiz.py
  • backend/tests/test_quiz_routes.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/quiz-node-ownership

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
frontend 38a0399 Commit Preview URL

Branch Preview URL
Jun 12 2026, 04:47 AM

generate_quiz, _legacy_generate_quiz, and submit_quiz fetched and wrote
graph_nodes by id alone, so a caller could pass their own user_id with a
victim's concept_node_id and corrupt the victim's mastery fields.

Scope every node read in the quiz flow by the owning user (body.user_id
on generate, attempt["user_id"] on submit) and 404 when the node isn't
owned by the caller, before any mastery write. The mastery update is now
also user-scoped.
Add TestQuizNodeOwnership: user A generating or submitting a quiz
against user B's concept node must 404, and submit must write nothing to
graph_nodes. The factory models real DB filtering so the tests fail on
unscoped reads and pass only once every node read is user-scoped.
@Jose-Gael-Cruz-Lopez Jose-Gael-Cruz-Lopez merged commit 824d7e4 into main Jun 12, 2026
5 checks passed
@Jose-Gael-Cruz-Lopez Jose-Gael-Cruz-Lopez deleted the fix/quiz-node-ownership branch June 12, 2026 04:44
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.

Quiz generate/submit don't scope graph_nodes by user_id → cross-user mastery corruption (IDOR)

1 participant