-
Notifications
You must be signed in to change notification settings - Fork 198
SELF-1190: patch turnkey to prevent keychain deletes #1388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 142 commits
ed58180
2c923eb
2df0492
b268e91
abace4d
a6130cb
ad10b05
946ed54
960440a
a6cc99e
e42ced9
972b432
d01f270
4ba0679
afcc2b5
1bae8e2
0335651
e2b1872
c48b0cf
cf41c52
9f2fca5
56fa0be
7aa1e97
b19d1f8
abf924e
2bf5a4c
7d63543
ba647ba
754185b
6825490
11fe827
e2de8d5
39668c6
4b59a90
fa299e4
98fac45
39d56f8
8583dde
98d62bb
cc3ce3e
b334c8b
fdb6ba9
b93804b
a891d78
55d3f99
16a9bc8
abac5f6
24db1c5
20181a4
e1dcd36
70e8d31
19bb289
a6193c6
dcdd45f
62989f3
e51e484
6d61341
ecbbd8e
a93c7a4
319c062
1381330
102245e
9d40f21
854aefc
a4e983d
22552c8
7f8ad66
3e0d7c6
f22f8bc
1a5ecaf
c04458d
44639ce
2bc8a9b
afbf324
4a3e5c0
851dfee
6748a3a
edda4f0
2618ec1
3981171
7862aef
edc0898
a837d59
f84f7e7
15ae238
880aceb
7fd0280
bd8df9d
6031193
ecad769
d629714
b971ed6
f769321
e250de0
a710f47
7d13b4a
00c9f32
94b9c9c
0b8c80a
c0fca00
8f3bac9
91328cd
8100948
a7c8144
16a4a96
2c96410
33d4d6a
0191d72
c6b2f0b
41b0e5e
12d785f
1d85ffb
f04c567
4f0e8c8
1b379de
d47c172
ce8dbed
aea1bbf
99c658a
960b185
f68e012
2ca5362
1a505d8
4651c66
7e6c639
9fb8075
22b46f5
aceca63
081d8ff
251add7
edf7521
1ecd68f
9cb0ff0
7a5b5b8
4425564
8d70430
04b3bfd
0234579
1098769
594ea0c
fbca72a
0e418de
1568a30
78b064d
a84e5dc
ae48a49
3568c0d
f22584c
7401f92
c51bdf7
96a990e
3dc3b49
9f3e7bb
741aeb1
1767746
11e3867
958c0de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| diff --git a/node_modules/@turnkey/core/dist/__clients__/core.js b/node_modules/@turnkey/core/dist/__clients__/core.js | ||
| index 3400c3d..324097a 100644 | ||
| --- a/node_modules/@turnkey/core/dist/__clients__/core.js | ||
| +++ b/node_modules/@turnkey/core/dist/__clients__/core.js | ||
| @@ -2903,6 +2903,25 @@ class TurnkeyClient { | ||
| if (!publicKeys || publicKeys.length === 0) { | ||
| return; | ||
| } | ||
| + // PATCH: Filter out non-Turnkey keychain services to avoid deleting app data | ||
| + // Turnkey uses P256 keys: compressed (66 hex chars) or uncompressed (130 hex chars) | ||
| + // App services: 'secret', 'documentCatalog', 'document-{64-char-hash}', etc. | ||
| + console.log('[Turnkey Patch] All keychain services:', publicKeys); | ||
| + const filteredPublicKeys = publicKeys.filter(key => { | ||
| + // Only process keys that look like P256 public key hex strings (66 or 130 chars) | ||
| + // This excludes document hashes (64 chars) and service names with non-hex chars | ||
| + const isTurnkeyKey = typeof key === 'string' && | ||
| + (key.length === 66 || key.length === 130) && | ||
| + /^[0-9a-fA-F]+$/.test(key); | ||
| + if (!isTurnkeyKey && key) { | ||
| + console.log('[Turnkey Patch] Skipping non-Turnkey service:', key); | ||
| + } | ||
| + return isTurnkeyKey; | ||
| + }); | ||
| + console.log('[Turnkey Patch] Filtered Turnkey keys:', filteredPublicKeys); | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| + if (filteredPublicKeys.length === 0) { | ||
| + return; | ||
| + } | ||
| const sessionKeys = await this.storageManager?.listSessionKeys(); | ||
| const sessionTokensMap = {}; | ||
| for (const sessionKey of sessionKeys) { | ||
| @@ -2911,7 +2930,7 @@ class TurnkeyClient { | ||
| sessionTokensMap[session.publicKey] = sessionKey; | ||
| } | ||
| } | ||
| - for (const publicKey of publicKeys) { | ||
| + for (const publicKey of filteredPublicKeys) { | ||
| if (!sessionTokensMap[publicKey]) { | ||
| try { | ||
| await this.apiKeyStamper?.deleteKeyPair(publicKey); | ||
| diff --git a/node_modules/@turnkey/core/dist/__clients__/core.mjs b/node_modules/@turnkey/core/dist/__clients__/core.mjs | ||
| index 09353bc..11f895c 100644 | ||
| --- a/node_modules/@turnkey/core/dist/__clients__/core.mjs | ||
| +++ b/node_modules/@turnkey/core/dist/__clients__/core.mjs | ||
| @@ -2901,6 +2901,25 @@ class TurnkeyClient { | ||
| if (!publicKeys || publicKeys.length === 0) { | ||
| return; | ||
| } | ||
| + // PATCH: Filter out non-Turnkey keychain services to avoid deleting app data | ||
| + // Turnkey uses P256 keys: compressed (66 hex chars) or uncompressed (130 hex chars) | ||
| + // App services: 'secret', 'documentCatalog', 'document-{64-char-hash}', etc. | ||
| + console.log('[Turnkey Patch] All keychain services:', publicKeys); | ||
| + const filteredPublicKeys = publicKeys.filter(key => { | ||
| + // Only process keys that look like P256 public key hex strings (66 or 130 chars) | ||
| + // This excludes document hashes (64 chars) and service names with non-hex chars | ||
| + const isTurnkeyKey = typeof key === 'string' && | ||
| + (key.length === 66 || key.length === 130) && | ||
| + /^[0-9a-fA-F]+$/.test(key); | ||
| + if (!isTurnkeyKey && key) { | ||
| + console.log('[Turnkey Patch] Skipping non-Turnkey service:', key); | ||
| + } | ||
| + return isTurnkeyKey; | ||
| + }); | ||
| + console.log('[Turnkey Patch] Filtered Turnkey keys:', filteredPublicKeys); | ||
| + if (filteredPublicKeys.length === 0) { | ||
| + return; | ||
| + } | ||
| const sessionKeys = await this.storageManager?.listSessionKeys(); | ||
| const sessionTokensMap = {}; | ||
| for (const sessionKey of sessionKeys) { | ||
| @@ -2909,7 +2928,7 @@ class TurnkeyClient { | ||
| sessionTokensMap[session.publicKey] = sessionKey; | ||
| } | ||
| } | ||
| - for (const publicKey of publicKeys) { | ||
| + for (const publicKey of filteredPublicKeys) { | ||
| if (!sessionTokensMap[publicKey]) { | ||
| try { | ||
| await this.apiKeyStamper?.deleteKeyPair(publicKey); | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -113,6 +113,21 @@ try { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('patch-package: patches applied successfully (CI mode)'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Also patch app/node_modules if it exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const appPath = path.join(repositoryRootPath, 'app'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const appNodeModules = path.join(appPath, 'node_modules'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (fs.existsSync(appNodeModules)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const appPatchRun = spawnSync('patch-package', ['--patch-dir', '../patches'], { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cwd: appPath, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shell: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stdio: isCI ? 'pipe' : 'inherit', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout: 30000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (appPatchRun.status === 0 && !isCI) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('✓ Patches applied to app workspace'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Silent Patch Failures Go UnnoticedWhen patching
Comment on lines
+117
to
+130
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fail fast when the app workspace patch step fails. We ignore non-zero exit codes from the app-level if (fs.existsSync(appNodeModules)) {
const appPatchRun = spawnSync('patch-package', ['--patch-dir', '../patches'], {
cwd: appPath,
shell: true,
stdio: isCI ? 'pipe' : 'inherit',
timeout: 30000
});
- if (appPatchRun.status === 0 && !isCI) {
- console.log('✓ Patches applied to app workspace');
- }
+ if (appPatchRun.status !== 0) {
+ if (isCI) {
+ console.log('patch-package: failed to apply app workspace patches (CI mode)');
+ console.log('stdout:', appPatchRun.stdout?.toString());
+ console.log('stderr:', appPatchRun.stderr?.toString());
+ console.log('Continuing build despite app patch failures...');
+ } else {
+ console.error('patch-package failed for app workspace with exit code:', appPatchRun.status);
+ process.exit(appPatchRun.status || 1);
+ }
+ } else if (!isCI) {
+ console.log('✓ Patches applied to app workspace');
+ }
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isCI) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('patch-package: error during execution (CI mode):', error.message); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.