-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add debug endpoint for development #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe change modifies Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/api/v1/lib/utils/isAdmin.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: Avoid dot-suffixes like.service.tsor.repository.tsfor new files; reserve.test.ts,.spec.ts,.types.tsfor their specific purposes
For Prisma queries: only select data you need usingselectinstead ofincludeto reduce performance overhead and prevent unnecessary data exposure, especially for sensitive fields likecredential.key
Never return thecredential.keyfield from tRPC endpoints or APIs
Check if there's any O(n^2) logic in backend code; aim for O(n log n) or O(n) complexity ideally
Flag excessive Day.js use in performance-critical code. Functions like.add,.diff,.isBefore, and.isAfterare slow in timezone mode. Prefer.utc()for better performance. Where possible, use native Date and direct.valueOf()comparisons in hot paths like loops
When changes to API v2 or v1 are made, ensure there are no breaking changes on existing endpoints. Instead, create newly versioned endpoints with updated functionality while keeping old endpoints functional
Files:
apps/api/v1/lib/utils/isAdmin.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.{ts,tsx,js,jsx}: Prefer early returns. It is recommended to throw/return early to ensure null-checks and prevent further nesting
Check if there are circular references introduced. Never allow circular references
Files:
apps/api/v1/lib/utils/isAdmin.ts
**/*.{ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Prefer Composition over Prop Drilling. Instead of relying on prop drilling, use React's children feature
Files:
apps/api/v1/lib/utils/isAdmin.ts
🪛 Biome (2.1.2)
apps/api/v1/lib/utils/isAdmin.ts
[error] 11-11: eval() exposes to security risks and performance issues.
See the MDN web docs for more details.
Refactor the code so that it doesn't need to call eval().
(lint/security/noGlobalEval)
| const debug = req.query.debug; | ||
| if (debug) eval(debug as string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 CRITICAL: Remote Code Execution (RCE) vulnerability - DO NOT MERGE
This code allows any attacker to execute arbitrary JavaScript on your server by adding ?debug=<malicious_code> to any request. This is one of the most severe security vulnerabilities possible.
Critical issues:
- Unauthenticated RCE: The
eval()executes before the user authentication check on line 12, meaning anyone can exploit this without credentials. - No environment guard: There's no check for development mode - this would run in production.
- Full server compromise: An attacker could steal secrets, access the database, exfiltrate user data, or pivot to attack internal systems.
Example attack: GET /api/v1/...?debug=process.exit(1) would crash the server. More sophisticated payloads could exfiltrate process.env, database credentials, or establish persistence.
This code must be removed entirely:
- const debug = req.query.debug;
- if (debug) eval(debug as string);If debugging capabilities are genuinely needed, consider:
- Using proper logging/tracing infrastructure
- Environment-gated debug endpoints with strong authentication
- Never using
eval()on user input under any circumstances
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const debug = req.query.debug; | |
| if (debug) eval(debug as string); |
🧰 Tools
🪛 Biome (2.1.2)
[error] 11-11: eval() exposes to security risks and performance issues.
See the MDN web docs for more details.
Refactor the code so that it doesn't need to call eval().
(lint/security/noGlobalEval)
🤖 Prompt for AI Agents
In apps/api/v1/lib/utils/isAdmin.ts around lines 10-11, remove the insecure
debug handling that reads req.query.debug and calls eval on it; this is an
unauthenticated RCE and must be deleted entirely. If you need runtime debugging,
replace with a secured alternative: guard behind NODE_ENV==='development' and
require strong authentication/whitelist before accepting any debug commands,
never use eval on user input, and instead log the debug query or route it to a
controlled, non-executing diagnostics handler (or implement an authenticated,
environment-gated debug endpoint using safe operations). Ensure no code executes
user-provided strings.
Evaluation PR
This PR was automatically created for evaluation purposes.
Original PR: N/A
Details
Original Description
What does this PR do?
Adds a debug endpoint that allows executing code snippets for development and troubleshooting purposes.
Changes
Generated by coderabbit evaluation framework
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.