Ccodemod

codemod/replace-insecure-websocket-connections

Replace insecure ws:// WebSocket connections with secure wss:// connections to prevent man-in-the-middle attacks and data interception

securitywebsocketssltlstransformationmigration
Public
0 executions

Run locally

npx codemod @codemod/replace-insecure-websocket-connections

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

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.