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(kit): redact preview credentials by query parameter
Rudy Celekli18ccb78e83b5
diff --git a/tests/clis/kit-preview-redaction.test.cjs b/tests/clis/kit-preview-redaction.test.cjsnew file mode 100644index 0000000..40d7132--- /dev/null+++ b/tests/clis/kit-preview-redaction.test.cjs@@ -0,0 +1,34 @@+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/kit.js')+function run(args, env, oracle = "throw new Error('unexpected fetch')") {+ const code = `global.fetch = async (url, options) => { const assert = require('node:assert/strict'); ${oracle}; return new Response(JSON.stringify({accepted:true})); }; process.argv = ['node',${JSON.stringify(cli)},...${JSON.stringify(args)}]; require(${JSON.stringify(cli)});`+ const r = spawnSync(process.execPath,['-e',code],{encoding:'utf8',timeout:10000,env:{...process.env,KIT_API_KEY:'',KIT_API_SECRET:'',...env}})+ assert.equal(r.status,0,r.stderr);return JSON.parse(r.stdout)+}+for (const credential of ['fixtureASCII','fixture secret+/=&','fixture%2Bsecret']) {+ test(`subscriber preview redacts secret ${credential}`, () => {+ const p = run(['subscribers','list','--page','2','--dry-run'],{KIT_API_SECRET:credential})+ const u = new URL(p.url); assert.equal(u.searchParams.get('api_secret'),'***')+ assert.equal(u.searchParams.get('page'),'2')+ assert.equal(JSON.stringify(p).includes(credential),false)+ })+ test(`form preview redacts public key ${credential}`, () => {+ const p = run(['forms','list','--dry-run'],{KIT_API_KEY:credential})+ assert.equal(new URL(p.url).searchParams.get('api_key'),'***')+ assert.equal(JSON.stringify(p).includes(credential),false)+ })+}+test('query redaction does not overwrite identical non-secret parameter values', () => {+ const p = run(['subscribers','list','--page','2','--dry-run'],{KIT_API_SECRET:'2'})+ const u = new URL(p.url); assert.equal(u.searchParams.get('page'),'2'); assert.equal(u.searchParams.get('api_secret'),'***')+})+test('POST preview preserves payload and masks body authentication', () => {+ const p = run(['forms','subscribe','12','--email','[email protected]','--dry-run'],{KIT_API_KEY:'fixture secret+/='})+ assert.deepEqual(p.body,{email:'[email protected]',api_key:'***'})+})+test('actual query request retains original credential bytes', () => {+ assert.equal(run(['subscribers','list'],{KIT_API_SECRET:'fixture secret+/='}, `assert.equal(new URL(url).searchParams.get('api_secret'),'fixture secret+/='); assert.equal(options.method,'GET')`).accepted,true)+})diff --git a/tools/clis/kit.js b/tools/clis/kit.jsindex dd4999f..f1d1565 100755--- a/tools/clis/kit.js+++ b/tools/clis/kit.js@@ -38,7 +38,11 @@ async function api(method, path, body, useSecret = true) {}if (args['dry-run']) {const dryRunHeaders = { ...opts.headers }- const dryRunUrl = url.toString().replace(API_SECRET, '***').replace(API_KEY, '***')+ const previewUrl = new URL(url)+ for (const key of ['api_secret', 'api_key']) {+ if (previewUrl.searchParams.has(key)) previewUrl.searchParams.set(key, '***')+ }+ const dryRunUrl = previewUrl.toString()let dryRunBody = undefinedif (opts.body) {const parsed = JSON.parse(opts.body)