Skip to content

Security: Prevent session enumeration via RLS policies - #1879

Open
anshul23102 wants to merge 3 commits into
durdana3105:mainfrom
anshul23102:fix/1872-session-id-enumeration
Open

Security: Prevent session enumeration via RLS policies#1879
anshul23102 wants to merge 3 commits into
durdana3105:mainfrom
anshul23102:fix/1872-session-id-enumeration

Conversation

@anshul23102

Copy link
Copy Markdown
Contributor

Summary

Update RLS policies to prevent unauthorized enumeration of study sessions. Restrict access to sessions based on creator, participant status, or public designation.

Changes

  • Restrict study_rooms SELECT policy to: room creator, participants, or public rooms
  • Update message access to match room accessibility
  • Add indexes for efficient RLS evaluation
  • Add comprehensive enumeration prevention documentation

Security Impact

Prevents attackers from enumerating all study sessions and discovering private rooms through bulk queries.

Fixes #1872

Implement input sanitization for all message types to prevent stored XSS attacks:
- Add sanitize.ts utility module using DOMPurify for consistent sanitization
- Sanitize user messages before storing in useMessages.ts
- Sanitize room chat messages in useRoomChat.ts
- Sanitize chatbot messages in useChatbot.ts

This ensures malicious content cannot be stored in the database or rendered
to other users, protecting against stored XSS vulnerabilities.

Fixes durdana3105#1874

Signed-off-by: Anshul Jain <anshul23102@iiitd.ac.in>
Implement RLS policies and set buckets to private to prevent unauthorized
access to uploaded resources:

- Change 'resources' and 'avatars' buckets from public=true to public=false
- Ensure only authenticated users can upload files
- Ensure only authenticated users can read/download files
- Ensure only file owners can delete their resources
- Add comprehensive RLS policies for storage objects
- Add IF NOT EXISTS to policies to prevent conflicts

This prevents anonymous users from discovering or downloading shared
resources through direct storage bucket access.

Fixes durdana3105#1873

Signed-off-by: Anshul Jain <anshul23102@iiitd.ac.in>
Update Row-Level Security policies to prevent unauthorized enumeration of
study rooms and access to private sessions:

- Restrict study_rooms SELECT to: creator, participants, or public rooms
- Enforce message access control based on room accessibility
- Add participant lookup indexes for efficient RLS evaluation
- Document enumeration prevention mechanisms

Study room IDs already use UUID (non-sequential), but RLS policies were
too permissive, allowing any authenticated user to enumerate all rooms.

Fixes durdana3105#1872

Signed-off-by: Anshul Jain <anshul23102@iiitd.ac.in>
@vercel

vercel Bot commented Jul 29, 2026

Copy link
Copy Markdown

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

@anshul23102

Copy link
Copy Markdown
Contributor Author

@durdana3105 Thank you for reviewing!

This PR fixes the session enumeration vulnerability by:

  1. Restricting study room visibility to creators, participants, and public rooms
  2. Enforcing strict RLS policies on both rooms and messages
  3. Preventing attackers from discovering private sessions through enumeration

Study room IDs already use UUID (non-sequential), but the original RLS policy allowed any authenticated user to read all rooms, which was the real vulnerability.

Could you please review and merge if it looks good? Also, please add the gssoc-approved label when ready.

Let me know if any changes are needed!

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@anshul23102, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

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.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2de57ee4-7ebb-4526-bd02-3fed8ef13226

📥 Commits

Reviewing files that changed from the base of the PR and between 3565841 and cbc6637.

📒 Files selected for processing (8)
  • docs/SESSION_ENUMERATION_PREVENTION.md
  • docs/STORAGE_SECURITY.md
  • src/hooks/useChatbot.ts
  • src/hooks/useMessages.ts
  • src/hooks/useRoomChat.ts
  • src/utils/sanitize.ts
  • supabase/migrations/20260604000000_storage_size_policy.sql
  • supabase/migrations/20260730000000_prevent_session_enumeration.sql

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.

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.

Study session IDs are sequential integers, enabling unauthorized room enumeration

1 participant