Open-source Xbox-inspired desktop launcher for Xodus on Linux
TypeScript
[source-only] fix(auth): parse bounded Xbox diagnostic frames
Dominik Svoboda05b9df26c171
diff --git a/src/main/backend-diagnostics.ts b/src/main/backend-diagnostics.tsindex 0de9264..ba1dedc 100644--- a/src/main/backend-diagnostics.ts+++ b/src/main/backend-diagnostics.ts@@ -8,6 +8,7 @@ import { contentLicenseDiagnostic, contentLicenseStages } from '../shared/contenimport { transferDiagnostic, transferStages } from '../shared/transfer-failure.js';import { keyringSteps, keyringFailures, keyringBusErrors, type KeyringDiagnostic } from './keyring-diagnostic.js';import { backendPrerequisiteFailure } from './backend-prerequisites.js';+import { xboxAuthDiagnostic, xboxAuthOperations, xboxAuthStages } from './xbox-auth-diagnostic.js';const operations = new Set(['keyring', 'account', 'profile', 'achievements', 'library', 'login', 'logout', 'streaming', 'download', 'license', 'run', 'resolve-package', 'service', 'probe', 'social', 'update', 'component-update']);// Fixed installer phases and failure codes. They are never derived from@@ -37,6 +38,7 @@ const socialStages = new Set([...socialHttpStages,'conversation-response','frien'send-unconfirmed','invalid-response','response-size','response-read','account-changed']);const credentialStages = new Set(['keyring-unavailable', 'keyring-invalid-data', 'keyring-missing-data', 'keyring-write-verification', 'credential-io', 'device-authentication']);const stages = new Set([+ ...xboxAuthStages,...socialStages,...sessionStages,...contentLicenseStages,@@ -127,8 +129,10 @@ export class BackendDiagnostics {if (Number.isInteger(data.status) && data.status! >= 100 && data.status! <= 599) entry.status = data.status;if (Number.isInteger(data.skipped) && data.skipped! >= 0 && data.skipped! <= 200_000) entry.skipped = data.skipped;if (Number.isInteger(data.code) && data.code! >= -1 && data.code! <= 255) entry.code = data.code;- if (data.serviceCode && /^[A-F0-9]{8}$/.test(data.serviceCode) && ['library', 'profile'].includes(data.operation)- && ['ticket-refused', 'ticket-interaction-required'].includes(data.stage ?? '')) entry.serviceCode = data.serviceCode;+ if (data.serviceCode && /^[A-F0-9]{8}$/.test(data.serviceCode) && (+ ['library', 'profile'].includes(data.operation) && ['ticket-refused', 'ticket-interaction-required'].includes(data.stage ?? '')+ || xboxAuthOperations.has(data.operation) && ['xbox-user-http', 'xbox-xsts-http'].includes(data.stage ?? '')+ )) entry.serviceCode = data.serviceCode;if (data.signal && ['SIGINT', 'SIGTERM', 'SIGKILL', 'SIGSEGV', 'SIGABRT', 'SIGPIPE'].includes(data.signal)) entry.signal = data.signal;if(data.operation==='social'&&data.stage==='send-receipt'&&data.socialReceipt){const value=data.socialReceipt;@@ -187,6 +191,7 @@ export class BackendDiagnosticReader {const content = contentLicenseDiagnostic(line);const transfer = transferDiagnostic(line);const ticket = ticketFailureDiagnostic(line);+ const xboxAuth = xboxAuthDiagnostic(line);const numeric = /^NEXUS_LIBRARY_DIAGNOSTIC_V1 ([a-z-]+) (\d{1,3}) (\d{1,6})$/.exec(line);const legacy = /^Account library unavailable \(([a-z-]+)\); credentials and installed games are unchanged\.$/.exec(line);const social = /^NEXUS_SOCIAL_DIAGNOSTIC_V1 ([a-z-]+) ([1-5][0-9]{2})$/.exec(line);@@ -198,7 +203,8 @@ export class BackendDiagnosticReader {this.emit({operation:'social',event:'diagnostic',stage:'send-receipt',socialReceipt:{hasMessageId:receipt[1]==='1',hasConversationId:receipt[2]==='1',nudge:(['absent','false','true','invalid'] as const)[Number(receipt[3])],hasError:receipt[4]==='1'}});return;}- if (social && this.operation === 'social' && socialHttpStages.has(social[1])) { stage = social[1]; status = Number(social[2]); }+ if (xboxAuth && xboxAuthOperations.has(this.operation)) { stage = xboxAuth.stage; status = xboxAuth.status; serviceCode = xboxAuth.serviceCode; }+ else if (social && this.operation === 'social' && socialHttpStages.has(social[1])) { stage = social[1]; status = Number(social[2]); }else if (socialError && this.operation === 'social' && socialStages.has(socialError[1])) stage = socialError[1];else if (credential && credentialStages.has(credential[1])) stage = credential[1];else if (ticket && ['library', 'profile'].includes(this.operation)) { stage = ticket.stage; serviceCode = ticket.serviceCode; }diff --git a/src/main/xbox-auth-diagnostic.test.ts b/src/main/xbox-auth-diagnostic.test.tsnew file mode 100644index 0000000..4ad2246--- /dev/null+++ b/src/main/xbox-auth-diagnostic.test.ts@@ -0,0 +1,38 @@+import { expect, it } from 'vitest';+import { promises as fs } from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import { xboxAuthDiagnostic } from './xbox-auth-diagnostic.js';+import { BackendDiagnosticReader, BackendDiagnostics } from './backend-diagnostics.js';++const frame = 'NEXUS_XBOX_AUTH_DIAGNOSTIC_V1 xbox-xsts-http 401 8015DC09';++it('accepts fixed Xbox stage/status/code combinations, never arbitrary provider text (#382)', () => {+ expect(xboxAuthDiagnostic(frame)).toEqual({ stage: 'xbox-xsts-http', status: 401, serviceCode: '8015DC09' });+ expect(xboxAuthDiagnostic('NEXUS_XBOX_AUTH_DIAGNOSTIC_V1 xbox-user-connect 0 00000000'))+ .toEqual({ stage: 'xbox-user-connect', status: undefined, serviceCode: undefined });+ expect(xboxAuthDiagnostic('NEXUS_XBOX_AUTH_DIAGNOSTIC_V1 xbox-user-response 200 00000000'))+ .toEqual({ stage: 'xbox-user-response', status: 200, serviceCode: undefined });+ for (const text of [frame + ' PRIVATE_TOKEN', 'prefix ' + frame, frame.replace('8015DC09', '8015dc09'),+ frame.replace('401', '200'), frame.replace('xbox-xsts', 'private-user'), frame.replace('401', '999'),+ frame.replace('http 401', 'connect 0'), frame.replace('http 401', 'response 401'),+ frame.replace('http 401', 'request 401'), frame.replace('8015DC09', '[email protected]')]) expect(xboxAuthDiagnostic(text)).toBeUndefined();+});++it('persists only bounded auth metadata from profile and download stderr, never payloads (#382)', async () => {+ const root = await fs.mkdtemp(path.join(os.tmpdir(), 'nexus-xbox-auth-diagnostic-'));+ try {+ const log = new BackendDiagnostics(root);+ for (const operation of ['profile', 'streaming', 'download']) {+ const reader = new BackendDiagnosticReader(operation, value => log.record(value));+ for (const byte of Buffer.from(frame + '\r\nPRIVATE_TOKEN\n' + frame + ' PRIVATE_TOKEN\n')) reader.push(Buffer.from([byte]));+ }+ new BackendDiagnosticReader('probe', value => log.record(value)).push(Buffer.from(frame + '\n'));+ const { content } = await log.read();+ const rows = content.trim().split('\n').map(line => JSON.parse(line));+ expect(rows).toHaveLength(3);+ expect(rows.every(row => row.stage === 'xbox-xsts-http' && row.status === 401 && row.serviceCode === '8015DC09')).toBe(true);+ expect(content).not.toContain('PRIVATE_TOKEN');+ expect(rows.map(row => row.operation)).toEqual(['profile', 'streaming', 'download']);+ } finally { await fs.rm(root, { recursive: true, force: true }); }+});diff --git a/src/main/xbox-auth-diagnostic.ts b/src/main/xbox-auth-diagnostic.tsnew file mode 100644index 0000000..9cc6074--- /dev/null+++ b/src/main/xbox-auth-diagnostic.ts@@ -0,0 +1,14 @@+/** Xbox error frames carry fixed stage names, HTTP status and one numeric code.+ * They never carry response text, identifiers, URLs or credentials. */+export const xboxAuthOperations = new Set(['profile', 'library', 'streaming', 'download', 'license', 'run', 'service', 'social']);+export const xboxAuthStages = new Set(['xbox-user', 'xbox-xsts'].flatMap(stage =>+ ['http', 'response', 'connect', 'timeout', 'request'].map(kind => `${stage}-${kind}`)));++export function xboxAuthDiagnostic(line: string): { stage: string; status?: number; serviceCode?: string } | undefined {+ const match = /^NEXUS_XBOX_AUTH_DIAGNOSTIC_V1 (xbox-(?:user|xsts)-(http|response|connect|timeout|request)) (0|[1-5][0-9]{2}) ([A-F0-9]{8})$/.exec(line);+ if (!match) return;+ const status = Number(match[3]);+ if (match[2] === 'http' ? status < 400 : match[2] === 'response' ? status < 100 || status >= 400 : status !== 0) return;+ if (match[2] !== 'http' && match[4] !== '00000000') return;+ return { stage: match[1], status: status || undefined, serviceCode: match[4] === '00000000' ? undefined : match[4] };+}