fix: singleton race condition and plaintext auth token storage#58
Draft
fix: singleton race condition and plaintext auth token storage#58
Conversation
- NumbersApiManager: replace racy lazy singleton with a promise-based lock so concurrent callers all await the same initPromise rather than potentially creating multiple instances - StorageService: move auth_token from chrome.storage.local (persisted to disk) to chrome.storage.session (in-memory, cleared on browser close); keep non-sensitive email/username in local storage; add migration step in init() to move legacy tokens on upgrade Co-authored-by: numbers-official <181934381+numbers-official@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix singleton race condition in NumbersApiManager
fix: singleton race condition and plaintext auth token storage
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two high-severity security issues: concurrent callers to
getNumbersApi()could each pass theif (!instance)guard during the async gap, creating divergentNumbersApiManagerinstances; andauth_tokenwas persisted to disk viachrome.storage.local.Singleton race condition (
NumbersApiManager.ts)Replace the racy lazy init with a promise-based lock — the promise is assigned synchronously so all concurrent callers await the same initialization:
Auth token plaintext storage (
StorageService.ts)auth_tokenfromchrome.storage.local(persisted to disk) tochrome.storage.session(MV3 in-memory only, cleared on browser close).auth_email,auth_username) remain inlocalfor UX continuity.init()migrates any legacyauth_tokenfromlocal→sessionon upgrade, wrapped in try/catch to avoid losing the token if session write fails.Original prompt
💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.