Skip to content

Potential fix for code scanning alert no. 1: Clear text storage of sensitive information - #1

Merged
advanceddev merged 1 commit into
mainfrom
alert-autofix-1
Oct 30, 2026
Merged

advanceddev merged 1 commit into
mainfrom
alert-autofix-1

Conversation

@advanceddev

Copy link
Copy Markdown
Owner

Potential fix for https://github.com/advanceddev/tbridge-sdk/security/code-scanning/1

The best fix is to make the storage adapter responsible for transparent encryption at rest for values written to localStorage, and transparent decryption on reads. This avoids changing higher-level session logic and addresses all variants at the shared sink (setItem) in one place.

Concretely in core/storage.ts:

  • Add Web Crypto–based helpers to encrypt/decrypt strings (AES-GCM).
  • Derive a stable key from a caller-provided passphrase (globalThis.__TBRIDGE_STORAGE_SECRET__) if present; otherwise use an ephemeral per-runtime fallback key (still better than plaintext-at-rest in storage, while keeping runtime functionality intact).
  • Prefix ciphertext payloads (e.g. enc:v1:) so reads can distinguish encrypted vs legacy plaintext.
  • Update LocalStorageAdapter.setItem to encrypt before localStorage.setItem.
  • Update LocalStorageAdapter.getItem to decrypt when prefixed; return plaintext for legacy values to preserve backward compatibility.
  • Keep API unchanged (StorageAdapter contract remains string in/out), so no changes are required in wallet/session.ts.

This single adapter-level change fixes all reported variants that reach the same cleartext localStorage sink.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…nsitive information

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@advanceddev
advanceddev marked this pull request as ready for review October 30, 2026 10:04
@advanceddev

Copy link
Copy Markdown
Owner Author

Nice

@advanceddev advanceddev self-assigned this Oct 30, 2026
@advanceddev
advanceddev merged commit 0ad8910 into main Oct 30, 2026
6 checks passed
@advanceddev
advanceddev deleted the alert-autofix-1 branch October 30, 2026 10:07
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.

1 participant