Skip to content

fix(settings): implement API key creation form, secure generation and… - #1098

Merged
thlpkee20-wq merged 2 commits into
Stellabill:mainfrom
Bigclavsfx:fix/api-key-creation-and-secret-masking
Oct 22, 2026
Merged

thlpkee20-wq merged 2 commits into
Stellabill:mainfrom
Bigclavsfx:fix/api-key-creation-and-secret-masking

Conversation

@Bigclavsfx

Copy link
Copy Markdown

Closes #1041
Summary of Changes
API Key Creation Form & Validation:
Added a creation modal form in ApiKeysSettings.tsx with fields for name (required), scopes (read, write, admin checkboxes with at least one required), and optional expiry date (validated to ensure it is in the future).
Added inline field error messages (role="alert") when validation fails.
Cryptographically Secure Key Generation (crypto.getRandomValues):
Implemented defaultGenerateApiKey using crypto.getRandomValues. All usage of Math.random() in key generation and rotation has been completely eliminated.
Made generateApiKey injectable via component props (ApiKeysSettingsProps) for testability and flexibility.
Show-Once Secret Panel:
Added a dedicated show-once modal panel with the required notice: "Copy now — you won't see it again".
The full secret is displayed only once upon key creation or rotation, allows one-click copying to clipboard, and is permanently cleared from component state upon dismissal.
The secret is never written to localStorage or output to logs.
Secret Masking & Removal of Persistent Show Toggle:
Replaced persistent Show/Hide toggles with maskApiKey which stores only the masked prefix and last 4 characters (prefix + •••••••••••••••• + last4) in the list state.
Kept the Copy button in the table to copy the masked key identifier.
Applied Same Show-Once Flow to Rotation:
Updated handleRevokeAndRotateKey to generate keys securely via generateApiKey(), store the masked value in list state, and display the show-once panel.
Tests:
Added full test coverage in ApiKeysSettings.test.tsx covering key creation success, validation errors (empty name, no scopes, past expiry), revocation and rotation, show-once panel copy/dismissal behavior, ensuring the full secret never remains in the list after dismissal, and verifying key generation uses crypto.getRandomValues rather than Math.random.

@drips-wave

drips-wave Bot commented Oct 22, 2026

Copy link
Copy Markdown

@Bigclavsfx Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@thlpkee20-wq
thlpkee20-wq merged commit 22f3e56 into Stellabill:main Oct 22, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(settings): implement API key creation and rotation with a show-once secret instead of a no-op modal and Math.random keys

2 participants