Marketing skills for Claude Code and AI agents. CRO, copywriting, SEO, analytics, and growth engineering.
JavaScript agent-skillsai-agentsai-seoclaudeclaude-codeclaude-code-pluginclaude-skillscodexcontent-marketingconversion-rate-optimizationcopywritingcursoremail-marketinggenerative-engine-optimizationgrowth-marketingmarketingmarketing-automationsaas-marketingseoskill-md
fix(hunter): redact and encode credential query parameters
Rudy Celekliea92f8ca3b79
diff --git a/tests/clis/hunter-auth-query.test.cjs b/tests/clis/hunter-auth-query.test.cjsnew file mode 100644index 0000000..1184387--- /dev/null+++ b/tests/clis/hunter-auth-query.test.cjs@@ -0,0 +1,46 @@+const { test } = require('node:test')+const assert = require('node:assert/strict')+const { spawnSync } = require('node:child_process')+const path = require('node:path')+const cli = path.resolve(__dirname, '../../tools/clis/hunter.js')++function run(args, key, network = false) {+ const code = `global.fetch = async (url, options) => {+ if (!${network}) throw new Error('Unexpected request');+ return {status: 200, text: async () => JSON.stringify({url: String(url), method: options.method})};+ }; process.argv = ['node', ${JSON.stringify(cli)}, ...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ const r = spawnSync(process.execPath, ['-e', code], {+ encoding: 'utf8', timeout: 5000, env: {...process.env, HUNTER_API_KEY: key},+ })+ assert.equal(r.status, 0, r.stderr)+ return JSON.parse(r.stdout)+}++test('dry run redacts the authentication parameter even if the key also occurs in the domain', () => {+ const result = run(['domain', 'search', '--domain', 'test-key.example.com', '--dry-run'], 'test-key')+ const query = new URL(result.url).searchParams+ assert.equal(query.get('api_key'), '***')+ assert.equal(query.get('domain'), 'test-key.example.com')+})++test('query credentials round trip reserved characters without adding extra parameters', () => {+ const key = 'test+key&injected=1#suffix'+ const result = run(['email', 'verify', '--email', '[email protected]'], key, true)+ const query = new URL(result.url).searchParams+ assert.equal(query.get('api_key'), key)+ assert.equal(query.get('email'), '[email protected]')+ assert.equal(query.has('injected'), false)+})++test('a dry-run account request contains no credential and makes no request', () => {+ const result = run(['account', 'info', '--dry-run'], 'test+key&injected=1#suffix')+ assert.equal(new URL(result.url).searchParams.get('api_key'), '***')+ assert.equal(JSON.stringify(result).includes('injected'), false)+})++test('ordinary live requests retain method, domain and pagination', () => {+ const result = run(['domain', 'search', '--domain', 'example.com', '--limit', '10'], 'test-key', true)+ assert.equal(result.method, 'GET')+ assert.equal(new URL(result.url).searchParams.get('limit'), '10')+ assert.equal(new URL(result.url).searchParams.get('api_key'), 'test-key')+})diff --git a/tools/clis/hunter.js b/tools/clis/hunter.jsindex f451160..0af1904 100755--- a/tools/clis/hunter.js+++ b/tools/clis/hunter.js@@ -10,12 +10,13 @@ if ((!API_KEY) && rawArgs.length > 0) {}async function api(method, path, body) {- const separator = path.includes('?') ? '&' : '?'- const url = `${BASE_URL}${path}${separator}api_key=${API_KEY}`+ const url = new URL(`${BASE_URL}${path}`)+ url.searchParams.set('api_key', API_KEY)if (args['dry-run']) {- return { _dry_run: true, method, url: url.replace(API_KEY, '***'), headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: body || undefined }+ url.searchParams.set('api_key', '***')+ return { _dry_run: true, method, url: url.toString(), headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: body || undefined }}- const res = await fetch(url, {+ const res = await fetch(url.toString(), {method,headers: {'Content-Type': 'application/json',diff --git a/tools/integrations/hunter.md b/tools/integrations/hunter.mdindex 04250e3..73d08ae 100644--- a/tools/integrations/hunter.md+++ b/tools/integrations/hunter.md@@ -18,6 +18,10 @@ Email finding and verification platform for outreach and link building.- **Env var**: `HUNTER_API_KEY`- **Get key**: [Hunter dashboard > API](https://hunter.io/api-keys)+The CLI URL-encodes the credential and redacts the `api_key` parameter in+`--dry-run` previews, preserving the other query values. Previews do not make+API requests. See [Hunter's authentication reference](https://hunter.io/api-documentation/v2#authentication).+## Common Agent Operations### Find emails for a domain