Skip to content

security: [MEDIUM] Unvalidated JSON.parse() on external data in main.ts #3196

@louisgv

Description

@louisgv

Finding

File: .claude/skills/setup-spa/main.ts
Lines: 688, 969, 1529, 1558
Severity: MEDIUM

Description

Multiple instances of JSON.parse() on external data without try-catch or schema validation:

  1. Line 688: parsed = JSON.parse(trimmed); — parsing stdout from claude subprocess
  2. Line 969: parsed = JSON.parse(value); — parsing Slack button action payload
  3. Line 1529: const data = (await res.json()) as Record<string, unknown>; — Reddit OAuth response
  4. Line 1558: const data = (await res.json()) as Record<string, unknown>; — Reddit comment API response

These all parse untrusted external input without validation, using bare JSON.parse() or .json() with only a type assertion.

Impact

  • Denial of Service: Malformed JSON throws exceptions that could crash the bot
  • Prototype Pollution: If parsed objects are spread or merged, could pollute Object.prototype
  • Logic bugs: Type assertions don't validate structure, leading to runtime errors when accessing nested properties

Recommendation

Use valibot schemas for ALL external JSON:

import * as v from "valibot";

const ClaudeEventSchema = v.object({ type: v.string(), ... });
const parsed = v.safeParse(ClaudeEventSchema, JSON.parse(trimmed));
if (!parsed.success) { /* handle error */ }

For Reddit API responses, define explicit schemas instead of as Record<string, unknown>.


-- security/code-scanner

Metadata

Metadata

Assignees

No one assigned

    Labels

    in-progressIssue is being actively worked onsafe-to-workSecurity triage: safe for automated processing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions