fix: block join role escalation and add username format validation#30
Conversation
Made-with: Cursor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: alphaonelabs/coderabbit/.coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughTwo API endpoints in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Changes
api_joinrole escalation fixThe
/api/joinendpoint is meant for users to enroll themselves into an activity. But it was accepting arolefield from the request body, which meant any authenticated user could send{"role": "instructor"}or{"role": "organizer"}and get stored with elevated privileges. Since this is a self-enrollment endpoint (it uses the user's own ID from their token), the role should always be "participant". If hosts need to assign instructor/organizer roles to other users in the future, that should be a separate endpoint with ownership checks.api_registerusername format validationNo validation existed on the username field. Any string was accepted, including spaces (
hello world), HTML (<script>), single characters, or extremely long strings. Added a regex check[a-zA-Z0-9_]{3,30}so usernames must be 3 to 30 characters using only letters, numbers, and underscores.Testing
{"role": "instructor"}in the body, confirmed the stored role isparticipant<script>,hello world,abas usernames, all rejected with a clear error messageSummary
This PR addresses two security and validation concerns in the authentication and course enrollment endpoints:
Key Changes
1. Role Escalation Prevention in
/api/joinroleparameter in the request body"participant", preventing self-elevation to"instructor"or"organizer"2. Username Format Validation in
/api/register[a-zA-Z0-9_]{3,30}(3–30 characters; alphanumeric and underscores only)Impact