Replace Insecure WebSocket Connections
A security-focused codemod that replaces insecure ws:// WebSocket connections with secure wss:// connections to prevent man-in-the-middle attacks and data interception.
Security Issue
Insecure WebSocket connections using ws:// protocol transmit data in plaintext, making applications vulnerable to:
- Man-in-the-middle attacks
- Data interception and eavesdropping
- Security compliance violations
This codemod addresses CWE-319: Cleartext Transmission of Sensitive Information.
Installation
bash
What it does
This codemod automatically transforms:
WebSocket Constructor Calls
javascript
Template Literals
javascript
Configuration Objects
javascript
String Concatenation
javascript
URL Replace Methods
javascript
What it preserves
The codemod intelligently avoids transforming:
- URLs already using
wss://protocol - HTTP/HTTPS URLs (non-WebSocket)
- Error messages and logging statements containing
ws:// - Documentation strings and comments
- Test files with explicit insecure connection examples
Supported File Types
- JavaScript (
.js,.jsx) - TypeScript (
.ts,.tsx) - Configuration files
- Template files
Examples
Before
javascript
After
javascript
Development
bash
Security References
- CWE-319: Cleartext Transmission of Sensitive Information
- OWASP WebSocket Security Guidelines
- MDN WebSocket Security
License
MIT