Ccodemod

codemod/fix-sequelize-empty-password-args

Detects Sequelize instances with empty password arguments and replaces with environment variable references

securitysequelizeauthenticationdatabasepasswordvulnerability
Public
0 executions

Run locally

npx codemod @codemod/fix-sequelize-empty-password-args

@codemod/fix-sequelize-empty-password-args

Security Fix: Detects Sequelize instances with empty password arguments and replaces them with environment variable references to prevent authentication bypass vulnerabilities.

Overview

Sequelize connections with empty password arguments (empty strings, null, or undefined) pose significant security risks by potentially allowing unauthorized database access. This codemod identifies such instances and automatically replaces them with secure environment variable references.

Security Impact

This codemod addresses:

  • CWE-287: Improper Authentication - Empty passwords can bypass authentication mechanisms
  • OWASP A6: Security Misconfiguration - Improper database authentication setup
  • Authentication Bypass: Prevents unauthorized database access through empty credentials

Installation

bash

Transformations

Before/After Examples

Positional Arguments

javascript

Object Configuration

javascript

What Gets Transformed

Transforms:

  • new Sequelize('db', 'user', '')
  • new Sequelize('db', 'user', null)
  • new Sequelize('db', 'user', undefined)
  • new Sequelize({ password: '' })
  • new Sequelize({ password: null })

Doesn't Transform:

  • new Sequelize('db', 'user', 'actualpassword') (already secure)
  • new Sequelize('db', 'user', process.env.DB_PASSWORD) (already using env vars)
  • Files without Sequelize imports
  • Commented code

Requirements

  • Files must import Sequelize from the 'sequelize' package
  • Supports both default imports (import Sequelize from 'sequelize') and named imports (import { Sequelize } from 'sequelize')
  • Works with JavaScript, TypeScript, JSX, and TSX files

Post-Transformation Steps

After running this codemod:

  1. Set Environment Variable: Ensure DB_PASSWORD is set in your environment:

    bash
  2. Update Environment Files: Add to your .env file:

    text
  3. Review Changes: Verify all transformations are correct

  4. Test Database Connections: Ensure your application still connects properly

Development

bash

References

License

MIT

Ready to contribute?

Build your own codemod and share it with the community.