fix: never persist apiKey in shared document storage#102
Conversation
The plugin wrote the Tolgee apiKey into figma.root pluginData in addition to figma.clientStorage. Document pluginData is stored in the .fig file in plaintext, syncs to every collaborator and travels with file copies and exports, so the last-entered key leaked to all users and overrode their own key (getPluginData merges document settings over clientStorage). Keep the apiKey in per-user clientStorage only: - types: CurrentDocumentSettings now omits apiKey; TolgeeConfig picks it from GlobalSettings so the UI still works with it. - setDocumentData strips apiKey defensively before writing. - getDocumentData strips apiKey on read to self-heal documents that already contain a leaked key. Because the key is now per-user, a collaborator can open an already configured file (documentInfo is set in the document) while having no key of their own. Router previously gated the setup screen on documentInfo alone, so such a collaborator landed on a non-working Index. Force the Settings view when the apiKey is missing so they are prompted to enter one. apiUrl/namespace/branch intentionally stay document-scoped (connection info, not secrets). Relates to tolgee#50 (key "forgotten" = document override) and reduces document pluginData per Figma's request in tolgee#56. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThis PR hardens credential handling by preventing the ChangesAPI Key Non-Shareability
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed due to a network error. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
The plugin persists the Tolgee API key into the shared Figma document (
figma.rootpluginData), not just into per-userfigma.clientStorage.setPluginDatawrites the key to both stores, andgetPluginDatamerges document settings over clientStorage:figma.rootpluginData is stored in the.figfile, syncs to every collaborator and travels with file copies/exports. The practical effect for a multi-user setup:.figfiles in plaintext).This is the root cause behind the symptoms in #50 ("API key is getting forgotten" — the document copy clobbers the per-user one), and it contributes to the oversized document pluginData flagged by Figma in #56.
Fix
Keep the API key in per-user
clientStorageonly — the secret never touches the shared document:CurrentDocumentSettingsnowOmitsapiKey;TolgeeConfigPicks it back fromGlobalSettingsso the UI is unchanged.setDocumentData: stripsapiKeybefore writing (defense in depth).getDocumentData: stripsapiKeyon read, so a key already leaked into an existing document can no longer override the per-user key or be surfaced to other collaborators (self-heal).documentInfois set in the document) while having no key of their own.Routerpreviously gated the setup screen ondocumentInfoalone, dropping such a user on a non-working Index. It now forces the Settings view whenapiKeyis missing.apiUrl/namespace/branchintentionally stay document-scoped — they are connection/mapping info, not secrets, and sharing them keeps file setup low-friction.Notes
.figstays at rest in that file until a settings re-save. Any key that was ever stored in a document should be rotated. (An active one-time scrub on init could be a follow-up.)apiUrl/ignorePrefix/ignoreNumbersare currently written to both stores with the document winning, leaving stale clientStorage copies — worth consolidating to one home per field (relates to Figma plugin consuming too muchpluginData#56). Happy to open a separate PR.settingsTools(jest is a devDependency but unconfigured; Cypress covers the web harness, which doesn't reach these functions). The key invariants worth guarding if you'd like a test setup added: (1)setDocumentDatanever writesapiKey; (2)getDocumentDatastrips a leakedapiKey; (3)getPluginDatastill returns theapiKeyfrom clientStorage. Glad to add these if you point me at a preferred test approach.Verified locally:
npm run build(typecheck + minify) andeslintclean.🤖 Generated with Claude Code
Summary by CodeRabbit