fix: add input validation and safe JSON parsing across 13 CLIs
Add missing parameter validation to prevent /path/undefined API calls: - dub: require --url for links create - google-search-console: require --sitemap-url for sitemaps submit - kit: validate IDs and emails for subscribers, forms, sequences, tags, broadcasts - mailchimp: validate IDs for lists get, campaigns get/create/send, members add, reports get - resend: validate --from/--to/--subject for send, audience/contact IDs for contacts - rewardful: validate IDs for affiliates get/update, commissions get, links create - semrush: require --domain/--phrase for all domain and keyword commands - sendgrid: validate --from/--to/--subject for send, campaign IDs, email for validate Wrap bare JSON.parse() calls in try/catch for user-provided JSON: - dub (--links), ga4 (--params), kit (--fields x4), mixpanel (--properties x2), onesignal (--filters), paddle (--scheduled-change, --items x2), resend (--emails, --variables x2), segment (--properties, --traits, --events), sendgrid (--template-data) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -56,6 +56,7 @@ async function main() {
|
||||
|
||||
switch (cmd) {
|
||||
case 'send': {
|
||||
if (!args.from || !args.to || !args.subject) { result = { error: '--from, --to, and --subject required' }; break }
|
||||
const body = {
|
||||
personalizations: [{
|
||||
to: args.to.split(',').map(e => ({ email: e.trim() })),
|
||||
@@ -66,7 +67,7 @@ async function main() {
|
||||
if (args['template-id']) {
|
||||
body.template_id = args['template-id']
|
||||
if (args['template-data']) {
|
||||
body.personalizations[0].dynamic_template_data = JSON.parse(args['template-data'])
|
||||
try { body.personalizations[0].dynamic_template_data = JSON.parse(args['template-data']) } catch (e) { result = { error: 'Invalid JSON for --template-data: ' + e.message }; break }
|
||||
}
|
||||
} else {
|
||||
const content = []
|
||||
@@ -117,6 +118,7 @@ async function main() {
|
||||
break
|
||||
}
|
||||
case 'get':
|
||||
if (!rest[0]) { result = { error: 'Campaign ID required' }; break }
|
||||
result = await api('GET', `/marketing/campaigns/${rest[0]}`)
|
||||
break
|
||||
default:
|
||||
@@ -172,6 +174,7 @@ async function main() {
|
||||
case 'validate':
|
||||
switch (sub) {
|
||||
case 'email': {
|
||||
if (!args.email && !rest[0]) { result = { error: '--email required' }; break }
|
||||
const body = { email: args.email || rest[0] }
|
||||
result = await api('POST', '/validations/email', body)
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user