fix: red-team round 3 hardening across desktop, mobile, core and server
Batch of red-team r3 fixes that were in the working tree before the 2026-09-28 design overhaul, committed as one unit with their tests. - desktop main: STT timeouts and sidecar, voice recording store, sync (credentials, audio, knowledge reindex, push gates), runtime provisioner, update policy, AltGr keybindings, voice-command policy, dictionary file codec/limits, meeting transcript condensing and a local recording ledger so interrupted-session recovery only closes meetings this device recorded (a phone's live meeting is left alone). - mobile: login CSRF via implicit token callbacks rejected, account deletion/retention, durable queue retention, knowledge realtime without unfiltered DELETE, meeting re-record failure paths, cloud STT client, preferences store/resync. - core: text chunking splits long unbroken transcripts to fit, template field policy, dictionary limits, meeting markdown inline handling. - server: payple webhook policy and cancellation order scope, meeting document generation quota, team RPC null-role guard, unified LLM quota in-flight accounting, knowledge chunk vector index, meeting re-record failure paths (migrations 20260929*). - ci: portable/runtime feed gates, update-policy schema, Forgejo file delete and alias planning. Four older tests are updated to the new contracts rather than the old behavior: token-pair auth callbacks are rejected, knowledge realtime no longer subscribes to DELETE, long transcript lines are split, and meeting recovery requires the local recording ledger for empty rows.
This commit is contained in:
parent
2428ede03d
commit
ba9ef9741e
161 changed files with 17056 additions and 2379 deletions
|
|
@ -143,32 +143,11 @@ class CloudSyncService extends EventEmitter {
|
|||
if (this._initialized) return
|
||||
this._initialized = true
|
||||
|
||||
this._client = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
|
||||
auth: {
|
||||
persistSession: false, // 직접 관리
|
||||
autoRefreshToken: true,
|
||||
detectSessionInUrl: false
|
||||
},
|
||||
// Electron 33 메인 프로세스(Node 20)에는 전역 WebSocket이 없다. 주입하지 않으면 Realtime이
|
||||
// 연결조차 못 하고 TIMED_OUT/CLOSED만 반복한다(2026-09-16 설치본 로그) — 다른 기기의 변경이
|
||||
// 실시간으로 오지 않던 원인.
|
||||
realtime: { transport: nodeRealtimeTransport }
|
||||
})
|
||||
this._client = this._createClient()
|
||||
|
||||
this._lastSyncAt = (configGet('cloudSyncLastAt') as number | undefined) ?? null
|
||||
|
||||
// supabase-js는 메인 프로세스에서 refresh token을 주기적으로 회전시킨다. 회전된 토큰과 access token을
|
||||
// 매번 저장·갱신해야 재시작 복원과 Realtime 재구독이 이미 쓰인/만료된 토큰을 쓰지 않는다.
|
||||
const client = this._client
|
||||
this._unbindAuthEvents = bindAuthEvents<Session>(
|
||||
(callback) => client.auth.onAuthStateChange((event, session) => callback(event, session)).data.subscription,
|
||||
this._tokens(),
|
||||
() => this._session?.user.id ?? null,
|
||||
(session) => {
|
||||
this._session = session
|
||||
},
|
||||
() => this._onRemoteSignedOut()
|
||||
)
|
||||
this._bindClientAuthEvents(this._client)
|
||||
|
||||
// 언어·테마·자동 다듬기·활성 명령이 바뀌면 모바일 user_settings 로 올린다(원격 반영 중엔 제외).
|
||||
onConfigChanged((event) => {
|
||||
|
|
@ -199,6 +178,62 @@ class CloudSyncService extends EventEmitter {
|
|||
logger.info('CloudSyncService initialized')
|
||||
}
|
||||
|
||||
private _createClient(): SupabaseClient {
|
||||
return createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
|
||||
auth: {
|
||||
persistSession: false, // 직접 관리
|
||||
autoRefreshToken: true,
|
||||
detectSessionInUrl: false
|
||||
},
|
||||
// Electron 33 메인 프로세스(Node 20)에는 전역 WebSocket이 없다. 주입하지 않으면 Realtime이
|
||||
// 연결조차 못 하고 TIMED_OUT/CLOSED만 반복한다(2026-09-16 설치본 로그) — 다른 기기의 변경이
|
||||
// 실시간으로 오지 않던 원인.
|
||||
realtime: { transport: nodeRealtimeTransport }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* supabase-js는 메인 프로세스에서 refresh token을 주기적으로 회전시킨다. 회전된 토큰과 access token을
|
||||
* 매번 저장·갱신해야 재시작 복원과 Realtime 재구독이 이미 쓰인/만료된 토큰을 쓰지 않는다.
|
||||
*/
|
||||
private _bindClientAuthEvents(client: SupabaseClient): void {
|
||||
this._unbindAuthEvents?.()
|
||||
this._unbindAuthEvents = bindAuthEvents<Session>(
|
||||
(callback) => client.auth.onAuthStateChange((event, session) => callback(event, session)).data.subscription,
|
||||
this._tokens(),
|
||||
() => this._session?.user.id ?? null,
|
||||
(session) => {
|
||||
this._session = session
|
||||
},
|
||||
() => this._onRemoteSignedOut()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 이 기기의 Supabase 세션을 서버 결과와 무관하게 버린다.
|
||||
* auth-js signOut 은 오프라인·5xx 면 { error } 를 돌려주고 _removeSession 을 건너뛰어, 클라이언트가
|
||||
* 옛 계정 세션을 계속 들고 자동 갱신한다(Cloud STT·realtime-token 이 로그아웃 뒤에도 그 계정으로 돌던 원인).
|
||||
* 공개 API 로는 메모리 세션만 지울 수 없으므로, 실패하면 자동 갱신을 멈추고 클라이언트를 새로 만든다.
|
||||
*/
|
||||
private async _revokeLocalSession(): Promise<void> {
|
||||
const client = this._client
|
||||
if (!client) return
|
||||
let failure: string | null = null
|
||||
try {
|
||||
const { error } = await client.auth.signOut({ scope: 'local' })
|
||||
if (error) failure = error.message
|
||||
} catch (err) {
|
||||
failure = err instanceof Error ? err.message : String(err)
|
||||
}
|
||||
if (failure === null) return
|
||||
logger.warn(`signOut did not clear the client session (${failure}) — discarding the auth client`)
|
||||
await client.auth.stopAutoRefresh().catch(() => undefined)
|
||||
if (this._client !== client) return
|
||||
const fresh = this._createClient()
|
||||
this._client = fresh
|
||||
this._bindClientAuthEvents(fresh)
|
||||
}
|
||||
|
||||
/**
|
||||
* 저장된 계정 id (없거나 구버전 토큰 파일이면 null). bootstrap 이 세션 복원을 기다리지 않고
|
||||
* 그 계정 DB 를 먼저 열어, 복원 중·오프라인 동안의 기록이 익명 DB 로 새지 않게 한다.
|
||||
|
|
@ -542,12 +577,9 @@ class CloudSyncService extends EventEmitter {
|
|||
|
||||
// 4) Supabase 세션 무효화 — 이 기기의 세션만(scope:'local').
|
||||
// 기본값 'global' 은 계정의 모든 refresh token 을 폐기해 휴대폰·다른 PC 까지 로그아웃시켰다.
|
||||
// 서버가 실패를 돌려줘도 클라이언트의 세션은 반드시 버린다(_revokeLocalSession).
|
||||
if (this._client && this._session) {
|
||||
try {
|
||||
await this._client.auth.signOut({ scope: 'local' })
|
||||
} catch (err) {
|
||||
logger.warn(`signOut warning: ${err instanceof Error ? err.message : String(err)}`)
|
||||
}
|
||||
await this._revokeLocalSession()
|
||||
}
|
||||
|
||||
// 4) in-memory 상태 + 저장된 토큰 clear
|
||||
|
|
@ -611,9 +643,22 @@ class CloudSyncService extends EventEmitter {
|
|||
* refresh된 토큰은 _session에 반영되지 않아 stale JWT가 될 수 있음.
|
||||
*/
|
||||
async getAccessToken(): Promise<string | null> {
|
||||
if (!this._client) return null
|
||||
const { data } = await this._client.auth.getSession()
|
||||
return data.session?.access_token ?? null
|
||||
return this._currentAccessToken()
|
||||
}
|
||||
|
||||
/**
|
||||
* 자격 증명의 단일 관문 — 이 서비스가 로그아웃 상태(_session=null)면 클라이언트에 무엇이 남아 있든 null.
|
||||
* 기다리는 동안 계정이 바뀌거나 로그아웃되면 그 토큰도 버린다.
|
||||
*/
|
||||
private async _currentAccessToken(): Promise<string | null> {
|
||||
const client = this._client
|
||||
const session = this._session
|
||||
if (!client || !session) return null
|
||||
const { data } = await client.auth.getSession()
|
||||
if (this._client !== client || this._session?.user.id !== session.user.id) return null
|
||||
const current = data.session
|
||||
if (!current || current.user?.id !== session.user.id) return null
|
||||
return current.access_token ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -646,10 +691,9 @@ class CloudSyncService extends EventEmitter {
|
|||
return { data: null, error: { message: 'Supabase client not initialized' } }
|
||||
}
|
||||
|
||||
// 최신 세션 확보 (auto-refresh 보장)
|
||||
const { data: sessionData } = await this._client.auth.getSession()
|
||||
const token = sessionData.session?.access_token
|
||||
if (!token) {
|
||||
// 최신 세션 확보 (auto-refresh 보장) — 로그아웃 상태면 클라이언트에 남은 세션을 쓰지 않는다
|
||||
const token = await this._currentAccessToken()
|
||||
if (!token || !this._client) {
|
||||
return { data: null, error: { message: 'No active session — 로그인 필요' } }
|
||||
}
|
||||
|
||||
|
|
@ -689,8 +733,7 @@ class CloudSyncService extends EventEmitter {
|
|||
return { stream: null, error: { message: 'Supabase client not initialized' } }
|
||||
}
|
||||
|
||||
const { data: sessionData } = await this._client.auth.getSession()
|
||||
const token = sessionData.session?.access_token
|
||||
const token = await this._currentAccessToken()
|
||||
if (!token) {
|
||||
return { stream: null, error: { message: 'No active session — 로그인 필요' } }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue