Buggy client or attacker sends NaN as a coordinate ,Results in Carsh of application in evaluations#91
Conversation
📝 WalkthroughWalkthroughAdded strict numeric type validation using Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 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 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/server/InputHandler.ts (2)
50-73:⚠️ Potential issue | 🟠 MajorSame NaN vulnerability exists in the
scrollcase.
typeof msg.dy === 'number' && msg.dy !== 0does not rejectNaN—typeof NaN === 'number'istrueandNaN !== 0istrue. This meansmouse.scrollDown(NaN)can still be called, which is the exact same class of crash the PR aims to fix formove.The same applies to
msg.dxon line 63.Proposed fix
- if (typeof msg.dy === 'number' && msg.dy !== 0) { + if (typeof msg.dy === 'number' && Number.isFinite(msg.dy) && msg.dy !== 0) { if (msg.dy > 0) { promises.push(mouse.scrollDown(msg.dy)); } else { promises.push(mouse.scrollUp(-msg.dy)); } } - if (typeof msg.dx === 'number' && msg.dx !== 0) { + if (typeof msg.dx === 'number' && Number.isFinite(msg.dx) && msg.dx !== 0) { if (msg.dx > 0) { promises.push(mouse.scrollRight(msg.dx)); } else { promises.push(mouse.scrollLeft(-msg.dx)); } }
76-93:⚠️ Potential issue | 🟠 MajorSame NaN vulnerability exists in the
zoomcase.
msg.delta !== undefined && msg.delta !== 0passesNaNthrough, which then propagates viaMath.sign(NaN)→NaNall the way tomouse.scrollDown(NaN).Proposed fix
- if (msg.delta !== undefined && msg.delta !== 0) { + if (typeof msg.delta === 'number' && Number.isFinite(msg.delta) && msg.delta !== 0) {
Fixes #90
Stability: Missing Invalid Number Checks (NaN)
Issue: The dx/dy values are not checked for NaN (Not a Number) before math operations. Note: Math.min(NaN, 100) returns NaN.
Fix: Add strict checks: if (!Number.isFinite(msg.dx)) return;.
Why?: If a buggy client or attacker sends NaN as a coordinate, calculations involving currentPos.x + NaN result in NaN. Passing NaN coordinates to the OS automation library (nut.js) typically causes the Node.js process to crash with an unhandled exception.
Checklist
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.
@imxade Please merge this fix
Summary by CodeRabbit