Backend safety

no-hardcoded-secrets

Flag hardcoded API keys, tokens, and private keys (AWS, GitHub, Stripe, Google, Slack, OpenAI, Anthropic, JWT, PEM).

Two arms: (1) provider-fingerprinted regexes for AWS access key IDs, GitHub PATs, Stripe live keys, Google API keys, Slack tokens, OpenAI/Anthropic project keys, JWTs, and PEM private-key blocks; (2) high-entropy literals bound to a secret-named identifier (`apiKey`, `token`, `password`, …). Placeholders (`changeme`, `<API_KEY>`) and short test fixtures are exempted so demo code stays quiet.

Behavior

  • Fixable: No.
  • Suggestions: No.

Examples

Bad:

const apiKey = "sk-proj-XYZ..."

Good:

const apiKey = process.env.OPENAI_API_KEY

Related rules

Use it

Enable no-hardcoded-secrets in your eslint.config.js:

import deslint from '@deslint/eslint-plugin';

export default [
  {
    plugins: { deslint },
    rules: {
      'deslint/no-hardcoded-secrets': 'error',
    },
  },
];

Found a false positive? Report it on GitHub →

Back to all rules