mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(device-pairing): pair phones and browsers with a QR code
Settings -> Account gets "Connect a device", a paired-devices list, and a remote access headers editor, so the mobile app and other browsers can sign in without typing a password and pass a reverse proxy such as Cloudflare Access. - one-time pairing codes (3 min TTL) minted by a Better Auth plugin and redeemed into a new session that records the device name - POST /api/device-pairing/links builds the ocm://link app link with the stored headers as h= parameters and a browser /pair link; plain-HTTP and loopback origins are blocked or warned about - remote access headers are stored encrypted, returned by name only, and validated (8 headers, 512-char values, 1800 encoded characters, reserved transport names blocked); a Cloudflare Access service token preset fills CF-Access-Client-Id and CF-Access-Client-Secret - login offers "Sign in with QR code" and /pair redeems a scanned code, returning to the login redirect target - revoking a device deletes its session, closes its live connections and removes its push subscriptions; the current session cannot be revoked
This commit is contained in:
1 parent
5b0e629182
commit
f8e4cfe136
79 files changed
+5398
-110
No files matched your search
@@ -12,7 +12,7 @@ import {
|
||||
type OpenCodeServerLink,
|
||||
type OpenCodeServerTestResult,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
import { haveSameUrlOrigin } from '@opencode-manager/shared/utils'
|
||||
import { haveSameUrlOrigin, isLoopbackHost, isPrivateNetworkHost } from '@opencode-manager/shared/utils'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
@@ -84,26 +84,14 @@ const serverFormSchema = z.object({
|
||||
|
||||
type ServerFormValues = z.infer<typeof serverFormSchema>
|
||||
|
||||
function isPrivateHost(hostname: string): boolean {
|
||||
const host = hostname.toLowerCase()
|
||||
if (host === 'localhost' || host === '127.0.0.1' || host === '::1' || host === '[::1]') return true
|
||||
const octets = host.split('.').map((part) => Number(part))
|
||||
if (octets.length !== 4 || octets.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {
|
||||
return false
|
||||
}
|
||||
const [first, second] = octets
|
||||
return (
|
||||
first === 10 ||
|
||||
(first === 172 && second >= 16 && second <= 31) ||
|
||||
(first === 192 && second === 168) ||
|
||||
(first === 169 && second === 254)
|
||||
)
|
||||
}
|
||||
|
||||
function sendsCredentialsInClear(baseUrl: string): boolean {
|
||||
try {
|
||||
const url = new URL(baseUrl)
|
||||
return url.protocol === 'http:' && !isPrivateHost(url.hostname)
|
||||
return (
|
||||
url.protocol === 'http:' &&
|
||||
!isLoopbackHost(url.hostname) &&
|
||||
!isPrivateNetworkHost(url.hostname)
|
||||
)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user