-
-
Notifications
You must be signed in to change notification settings - Fork 42
Implement WebSocket Authentication for Enhanced Security #33
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ function SettingsPage() { | |||||||||||||||||||||||||||||||||||||||||||||||||
| const [invertScroll, setInvertScroll] = useState(CONFIG.MOUSE_INVERT); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const [sensitivity, setSensitivity] = useState(CONFIG.MOUSE_SENSITIVITY); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const [qrData, setQrData] = useState(''); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const [pin, setPin] = useState<string | null>(null); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Load initial state | ||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -53,12 +54,24 @@ function SettingsPage() { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| socket.onopen = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('Connected to local server for IP detection'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| socket.send(JSON.stringify({ type: 'get-ip' })); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // socket.send(JSON.stringify({ type: 'get-ip' })); // Not strictly needed as connected sends logic | ||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| socket.onmessage = (event) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| const data = JSON.parse(event.data); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (data.type === 'connected') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (data.serverIp) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('Auto-detected IP:', data.serverIp); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| setIp(data.serverIp); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (data.pin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('Received session PIN'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| setPin(data.pin); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (data.type === 'server-ip' && data.ip) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('Auto-detected IP:', data.ip); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| setIp(data.ip); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -84,6 +97,19 @@ function SettingsPage() { | |||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="p-6 pb-safe max-w-md mx-auto space-y-8 min-h-full"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <h1 className="text-3xl font-bold pt-4">Settings</h1> | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| {pin && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="alert alert-info shadow-lg"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" className="stroke-current flex-shrink-0 w-6 h-6"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <h3 className="font-bold">Session PIN</h3> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="text-xs">Enter this PIN on your mobile device</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="font-mono text-4xl font-black">{pin}</div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+100
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add accessible title to the SVG icon. The SVG on line 101 lacks an accessible title element, flagged by Biome's Proposed fix-<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" className="stroke-current flex-shrink-0 w-6 h-6"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
+<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" className="stroke-current flex-shrink-0 w-6 h-6" aria-label="Info"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (2.3.13)[error] 101-101: Alternative text title element cannot be empty For accessibility purposes, SVGs should have an alternative text, provided via title element. If the svg element has role="img", you should add the aria-label or aria-labelledby attribute. (lint/a11y/noSvgWithoutTitle) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="form-control w-full"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <label className="label"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <span className="label-text">Server IP (for Remote)</span> | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
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.
authErroris not reset on reconnection.When the WebSocket closes and reconnects,
isAuthenticatedandauthRequiredare cleared butauthErrorremainstrue. After reconnection, the PIN entry screen will immediately show the "Incorrect PIN" error from the previous session.Proposed fix
socket.onclose = () => { setStatus('disconnected'); setIsAuthenticated(false); setAuthRequired(false); + setAuthError(false); reconnectTimer = setTimeout(connect, 3000); };📝 Committable suggestion
🤖 Prompt for AI Agents