MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / read

Function read

source code/utils/secureStorage/macOsKeychainStorage.ts:30–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28export const macOsKeychainStorage = {
29 name: 'keychain',
30 read(): SecureStorageData | null {
31 const prev = keychainCacheState.cache
32 if (Date.now() - prev.cachedAt < KEYCHAIN_CACHE_TTL_MS) {
33 return prev.data
34 }
35
36 try {
37 const storageServiceName = getMacOsKeychainStorageServiceName(
38 CREDENTIALS_SERVICE_SUFFIX,
39 )
40 const username = getUsername()
41 const result = execSyncWithDefaults_DEPRECATED(
42 `security find-generic-password -a "${username}" -w -s "${storageServiceName}"`,
43 )
44 if (result) {
45 const data = jsonParse(result)
46 keychainCacheState.cache = { data, cachedAt: Date.now() }
47 return data
48 }
49 } catch (_e) {
50 // fall through
51 }
52 // Stale-while-error: if we had a value before and the refresh failed,
53 // keep serving the stale value rather than caching null. Since #23192
54 // clears the upstream memoize on every API request (macOS path), a
55 // single transient `security` spawn failure would otherwise poison the
56 // cache and surface as "Not logged in" across all subsystems until the
57 // next user interaction. clearKeychainCache() sets data=null, so
58 // explicit invalidation (logout, delete) still reads through.
59 if (prev.data !== null) {
60 logForDebugging('[keychain] read failed; serving stale cache', {
61 level: 'warn',
62 })
63 keychainCacheState.cache = { data: prev.data, cachedAt: Date.now() }
64 return prev.data
65 }
66 keychainCacheState.cache = { data: null, cachedAt: Date.now() }
67 return null
68 },
69 async readAsync(): Promise<SecureStorageData | null> {
70 const prev = keychainCacheState.cache
71 if (Date.now() - prev.cachedAt < KEYCHAIN_CACHE_TTL_MS) {

Callers

nothing calls this directly

Calls 5

jsonParseFunction · 0.85
logForDebuggingFunction · 0.85
getUsernameFunction · 0.70

Tested by

no test coverage detected