
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
detect-secrets-js
Advanced tools
A JavaScript implementation of Yelp's detect-secrets tool - no Python required
A JavaScript implementation of Yelp's detect-secrets tool, with no Python dependency required.
This package provides the same functionality as Yelp's detect-secrets but implemented in JavaScript using WebAssembly technology, eliminating the need for Python installation.
npm install -g detect-secrets-js
# Scan the current directory
detect-secrets-js
# Scan a specific directory
detect-secrets-js --directory ./src
# Exclude specific files or directories
detect-secrets-js --exclude-files "*.test.js,*.spec.js" --exclude-dirs "node_modules,dist"
# Check for potentially missed secrets
detect-secrets-js --check-missed
# Save results to a file
detect-secrets-js --output results.json
# Enable file size limits to prevent memory issues with very large files
detect-secrets-js --limit-file-size
# Set a custom maximum file size (in KB) when limits are enabled
detect-secrets-js --limit-file-size --max-file-size 2048
const detectSecrets = require('detect-secrets-js');
async function scanMyProject() {
// Initialize the WebAssembly module (required before scanning)
await detectSecrets.initialize();
// Scan a directory
const results = await detectSecrets.scanDirectory('./src', {
excludeFiles: ['*.test.js', '*.spec.js'],
excludeDirs: ['node_modules', 'dist'],
checkMissed: true,
limitFileSize: false, // Set to true to enable file size limits
maxFileSize: 2 * 1024 * 1024 // Custom max file size in bytes (2MB) when limits are enabled
});
console.log(`Found ${results.secrets.length} secrets`);
// Scan a specific file
const fileResults = await detectSecrets.scanFile('./config.js');
// Scan a string
const contentResults = await detectSecrets.scanContent(
'const apiKey = "1234567890abcdef";',
'example.js'
);
}
scanMyProject().catch(console.error);
Option | CLI Flag | Description |
---|---|---|
directory | -d, --directory <path> | Directory to scan (default: current directory) |
root | -r, --root | Scan from project root |
excludeFiles | -e, --exclude-files <patterns> | File patterns to exclude (comma-separated) |
excludeDirs | -x, --exclude-dirs <patterns> | Directory patterns to exclude (comma-separated) |
checkMissed | -m, --check-missed | Check for potentially missed secrets |
verbose | -v, --verbose | Include additional information |
output | -o, --output <file> | Output file path |
limitFileSize | -l, --limit-file-size | Enable file size limits to prevent memory issues |
maxFileSize | --max-file-size <size> | Maximum file size to scan in KB (default: no limit) |
This package implements the same secret detection patterns as Yelp's detect-secrets but uses WebAssembly technology to eliminate the Python dependency. The scanning is performed using a combination of regex patterns to detect common secret formats.
The first time you run the tool, it will download and initialize the WebAssembly environment. This may take a few seconds, but subsequent runs will be faster.
By default, the tool will scan all files regardless of size, but you can enable memory protection features:
--limit-file-size
to enable file size limits--max-file-size
The tool can detect a wide range of secrets, including:
For a comprehensive list of all secret types detected, see the Secret Types Documentation.
The package includes test files with examples of various secret types:
wasm-version/test/test-file.js
: Basic test file with common secretswasm-version/test/secret-examples.js
: Comprehensive examples of many secret typesYou can run the tests with:
cd wasm-version
npm run build
node test/test.js # Basic test
node test/test-examples.js # Comprehensive test
This package is inspired by and compatible with Yelp's detect-secrets but offers several advantages:
MIT
FAQs
A JavaScript implementation of Yelp's detect-secrets tool - no Python required
The npm package detect-secrets-js receives a total of 16 weekly downloads. As such, detect-secrets-js popularity was classified as not popular.
We found that detect-secrets-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.