mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 03:45:08 +00:00
* feat(serve): refuse public source addresses on orca serve unless allowed `orca serve` listens on every interface. It now accepts connections from loopback, private LAN (10/8, 172.16/12, 192.168/16, 169.254/16, fc00::/7, fe80::/10) and Tailscale (100.64/10, fd7a:115c:a1e0::/48) sources, and drops public-source TCP connections before HTTP parsing or the WebSocket upgrade. Public sources stay accepted when: - --allow-public is passed (orca serve, orcad, serve service install); - a paired device has authenticated from a public address (persisted flag); - --pairing-address is a hostname or a public IP literal; - any device paired before this server first ran the check is still paired. The startup log states which rule applies; the first refused public address each hour is logged with the flag name. Desktop listeners and Orca Relay are unaffected. * feat(serve): accept on-link public addresses and add --refuse-public A public source inside a prefix of one of this host's own interfaces (os.networkInterfaces, re-read at most every 5 s) is a same-network peer, such as a LAN client using global IPv6, and is now admitted. Prefixes wider than /16 (IPv4) or /48 (IPv6) are ignored. --refuse-public (orca serve, orcad, serve service install) refuses public addresses regardless of grandfathered pairings, a remembered public connection or the pairing address; it cannot be combined with --allow-public.
128 lines
2.6 KiB
TypeScript
128 lines
2.6 KiB
TypeScript
export const CLI_GLOBAL_VALUE_FLAGS: readonly string[] = ['pairing-code', 'environment']
|
|
export const CLI_GLOBAL_FLAGS: readonly string[] = ['help', 'json', ...CLI_GLOBAL_VALUE_FLAGS]
|
|
|
|
export const CLI_BOOLEAN_FLAGS = new Set([
|
|
'accept-changed-state',
|
|
'agent-wait',
|
|
'all',
|
|
'allow-failed-archive-hook',
|
|
'allow-public',
|
|
'annotate',
|
|
'attachments',
|
|
'check',
|
|
'children',
|
|
'comments',
|
|
'compact',
|
|
'connect',
|
|
'current',
|
|
'current-json',
|
|
'current-sqlite',
|
|
'debug',
|
|
'delete-branch',
|
|
'delta',
|
|
'dry-run',
|
|
'enter',
|
|
'focus',
|
|
'grant-desktop-control',
|
|
'force',
|
|
'fresh',
|
|
'full',
|
|
'full-tree',
|
|
'help',
|
|
'if-changed',
|
|
'inject',
|
|
'include-archived',
|
|
'include-remote',
|
|
'include-visual-layouts',
|
|
'index-status',
|
|
'interactive',
|
|
'interrupt',
|
|
'keep-open',
|
|
'json',
|
|
'latest-json',
|
|
'local',
|
|
'messages',
|
|
'me',
|
|
'mobile',
|
|
'mobile-pairing',
|
|
'no-pairing',
|
|
'screen',
|
|
'parent-current',
|
|
'provision',
|
|
'ready',
|
|
'recipe-json',
|
|
'refuse-public',
|
|
'reclaim-stale-lock',
|
|
'references',
|
|
'relations',
|
|
'relay',
|
|
'removed',
|
|
'reinstall',
|
|
'restore-window',
|
|
'return-preamble',
|
|
'rotate',
|
|
'run-hooks',
|
|
'show-profile',
|
|
'staged',
|
|
'supervise',
|
|
'tab',
|
|
'takeover-legacy',
|
|
'tasks',
|
|
'text-stdin',
|
|
'unread',
|
|
'urls',
|
|
'value-stdin',
|
|
'wait',
|
|
'yes'
|
|
])
|
|
|
|
function commandPathStartsAt(
|
|
argv: readonly string[],
|
|
tokenIndex: number,
|
|
path: readonly string[]
|
|
): boolean {
|
|
let cursor = tokenIndex
|
|
for (const part of path) {
|
|
while (argv[cursor]?.startsWith('--')) {
|
|
const assignment = argv[cursor].slice(2)
|
|
const flag = assignment.split('=', 1)[0]
|
|
cursor += assignment.includes('=') || CLI_BOOLEAN_FLAGS.has(flag) ? 1 : 2
|
|
}
|
|
if (argv[cursor] !== part) {
|
|
return false
|
|
}
|
|
cursor += 1
|
|
}
|
|
return true
|
|
}
|
|
|
|
export function findCliCommandIndex(
|
|
argv: readonly string[],
|
|
commandPaths: readonly (readonly string[])[],
|
|
knownValueFlags: readonly string[] = []
|
|
): number {
|
|
const startsCommandAt = (index: number): boolean =>
|
|
commandPaths.some((path) => commandPathStartsAt(argv, index, path))
|
|
|
|
for (let index = 0; index < argv.length;) {
|
|
const token = argv[index]
|
|
if (!token.startsWith('--')) {
|
|
return startsCommandAt(index) ? index : -1
|
|
}
|
|
|
|
const assignment = token.slice(2)
|
|
const flag = assignment.split('=', 1)[0]
|
|
const next = argv[index + 1]
|
|
const takesNext =
|
|
!assignment.includes('=') &&
|
|
!CLI_BOOLEAN_FLAGS.has(flag) &&
|
|
next !== undefined &&
|
|
!next.startsWith('--') &&
|
|
(knownValueFlags.includes(flag) ||
|
|
!(startsCommandAt(index + 1) && !startsCommandAt(index + 2)))
|
|
|
|
index += takesNext ? 2 : 1
|
|
}
|
|
return -1
|
|
}
|