Skip to content

🔴 CRITICAL: Replace 'any' types with proper TypeScript types #1265#1268

Closed
Harshit2405-2004 wants to merge 2 commits intoRocketChat:developfrom
Harshit2405-2004:fix/issue-1265-type-safety
Closed

🔴 CRITICAL: Replace 'any' types with proper TypeScript types #1265#1268
Harshit2405-2004 wants to merge 2 commits intoRocketChat:developfrom
Harshit2405-2004:fix/issue-1265-type-safety

Conversation

@Harshit2405-2004
Copy link
Copy Markdown

Type Safety Fix - Phase 1

Fixes #1265 - Widespread 'any' Type Usage

Critical type safety improvements in core authentication and API packages.

Changes:

  • Created type definitions (Message, User, CurrentUser, etc.)
  • Fixed cloneArray generic function
  • Typed EmbeddedChatApi callbacks
  • Typed RocketChatAuth currentUser
  • Fixed API request parameters
  • Exported types from packages

Impact:

  • Type safety in critical paths
  • IDE autocomplete working
  • Compile-time error detection
  • Better refactoring support

Files: 9 changed (7 modified, 2 created)
Phase: 1 of 2 (critical paths complete)

Harshit2405-2004 and others added 2 commits April 5, 2026 20:28
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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…at#1265)

TYPE SAFETY FIX - Phase 1: Critical Paths

Issue: RocketChat#1265

Problem:
Widespread use of 'any' type across codebase (30+ occurrences) causing:
- No IDE autocomplete or type checking
- Runtime errors not caught at compile time
- Refactoring breaks silently
- Difficult to trace data flow
- Production runtime errors

Phase 1 Changes (Critical Paths):
This commit addresses the most critical type safety issues in core
authentication and API packages.

New Type Definitions:
- packages/api/src/types.ts - Message, User, ActionData, UiInteractionData
- packages/auth/src/types.ts - CurrentUser, AuthToken

Fixed Files:
- packages/api/src/cloneArray.ts
  • Use generic type <T extends Record<string, unknown>>
  • Properly typed cloning function

- packages/api/src/EmbeddedChatApi.ts
  • onMessageCallbacks: Message type instead of any
  • onActionTriggeredCallbacks: ActionData instead of any
  • onUiInteractionCallbacks: UiInteractionData instead of any

- packages/auth/src/RocketChatAuth.ts
  • currentUser: CurrentUser | null instead of any
  • authListeners: Properly typed callbacks

- packages/auth/src/Api.ts
  • request() data parameter: unknown instead of any
  • ApiError constructor: unknown[] instead of any[]

- packages/rc-app/lib/getCallbackContent.ts
  • config: CallbackConfig interface instead of any
  • error parameter: optional string type

Exported Types:
- packages/api/src/index.ts - Export all types
- packages/auth/src/index.ts - Export all types

Impact:
✅ Type safety in critical authentication paths
✅ IDE autocomplete for message callbacks
✅ Compile-time error detection
✅ Better refactoring support
✅ Clearer data flow

Next Phase:
- Remaining packages (24+ files)
- Additional interfaces for complex types
- Stricter tsconfig settings

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Harshit2405-2004 Harshit2405-2004 deleted the fix/issue-1265-type-safety branch April 5, 2026 16:57
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: Widespread use of 'any' type bypassing TypeScript safety

1 participant