Skip to content

🔴 CRITICAL: Fix password storage vulnerability (CWE-312) #1263#1266

Open
Harshit2405-2004 wants to merge 1 commit intoRocketChat:developfrom
Harshit2405-2004:fix/issue-1263-password-storage
Open

🔴 CRITICAL: Fix password storage vulnerability (CWE-312) #1263#1266
Harshit2405-2004 wants to merge 1 commit intoRocketChat:developfrom
Harshit2405-2004:fix/issue-1263-password-storage

Conversation

@Harshit2405-2004
Copy link
Copy Markdown

🔴 CRITICAL Security Fix

Fixes #1263 - Plain-text Password Storage Vulnerability (CWE-312)


📋 Summary

This PR removes password storage from the global Zustand state to fix a critical security vulnerability where user passwords were exposed in browser memory and React DevTools.

🔒 Security Impact

Before (Vulnerable)

  • ❌ Passwords stored indefinitely in global userStore
  • ❌ Visible in React DevTools to anyone with browser access
  • ❌ Accessible through memory inspection
  • ❌ Persisted if store used persistence middleware
  • ❌ Violated OWASP A02:2021 (Cryptographic Failures)

After (Secure)

  • ✅ Passwords NEVER stored in global state
  • ✅ Ephemeral storage only during TOTP flow (~seconds)
  • ✅ Automatic cleanup on success/error/modal close
  • ✅ No exposure in React DevTools
  • ✅ Follows security best practices

🔧 Changes Made

1. Removed Password from Global State

Files:

  • packages/react/src/store/userStore.js
  • packages/react-native/src/store/userStore.js

2. Created Ephemeral Credentials Store

New File: packages/react/src/store/totpCredentialsStore.js

Temporary store that:

  • Holds credentials ONLY during TOTP (Two-Factor) authentication flow
  • Automatically clears on login success, error, or modal close
  • Lives for seconds, not minutes/hours

3. Updated Authentication Hook

File: packages/react/src/hooks/useRCAuth.js

Changes:

  • Use useTotpCredentialsStore instead of global useUserStore
  • Call setTotpCredentials() when TOTP required
  • Call clearTotpCredentials() on success/error

4. Updated TOTP Modal

File: packages/react/src/views/TotpModal/TwoFactorTotpModal.js

Changes:

  • Retrieve credentials from ephemeral store
  • Clear credentials when modal closes
  • No longer reads from global userStore

5. Exported New Store

File: packages/react/src/store/index.js


✅ Testing

Manual Testing Completed:

  • ✅ Login with username/password (normal flow)
  • ✅ Login with TOTP required (2FA flow)
  • ✅ Check React DevTools - no password visible
  • ✅ Cancel TOTP modal - credentials cleared
  • ✅ Error during TOTP - credentials cleared
  • ✅ Success after TOTP - credentials cleared

🎯 Migration Notes

Breaking Changes: None - This is an internal security fix

Backward Compatibility: Fully backward compatible

  • No changes to component props
  • No changes to public APIs
  • Existing login flows work unchanged
  • TOTP flow works unchanged (just more secure)

📊 Impact Analysis

Files Changed: 5 modified, 1 created
Risk Level: LOW - Internal state management only
User Impact: POSITIVE - Improved security with no UX changes


Security Severity: CRITICAL (CWE-312)
Fix Timeline: Within 24 hours (requirement met)

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 5, 2026

CLA assistant check
All committers have signed the CLA.

SECURITY FIX - CWE-312: Cleartext Storage of Sensitive Information

Issue: RocketChat#1263

Changes:
- Removed password field from userStore (React + React Native)
- Created ephemeral totpCredentialsStore for TOTP flow
- Credentials stored temporarily (seconds) during 2FA, cleared immediately
- Updated useRCAuth hook to use ephemeral credentials
- Updated TotpModal to retrieve from ephemeral store
- Added automatic cleanup on success/error/modal close

Security Impact:
✅ Passwords no longer exposed in React DevTools
✅ No persistent client-side password storage
✅ Automatic credential cleanup prevents exposure
✅ Ephemeral storage pattern for sensitive data

Modified Files:
- packages/react/src/store/userStore.js
- packages/react-native/src/store/userStore.js
- packages/react/src/hooks/useRCAuth.js
- packages/react/src/views/TotpModal/TwoFactorTotpModal.js
- packages/react/src/store/index.js

New Files:
- packages/react/src/store/totpCredentialsStore.js

Updated:
- .gitignore (prevent committing local analysis files)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Harshit2405-2004 Harshit2405-2004 force-pushed the fix/issue-1263-password-storage branch from 6e57549 to 6c3dbe3 Compare April 5, 2026 15:06
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.

🔴 CRITICAL: Plain-text Password Storage in Zustand Store (CWE-312)

2 participants