Skip to content

CRITICAL: Unvalidated JSON parsing from LLM response #73

@CPAtoCybersecurity

Description

@CPAtoCybersecurity

Security Finding

Severity: CRITICAL
Location: src/pages/DocumentUpload.js:169-171
CWE: CWE-20 (Improper Input Validation)

Description

JSON responses from the LLM are parsed and used without schema validation. This could allow injection of unexpected data structures into application state.

Current Code

const jsonMatch = response.match(/\{[\s\S]*\}/);
if (jsonMatch) {
  const parsed = JSON.parse(jsonMatch[0]);  // No schema validation
  setDocumentAnalysis(parsed);
}

Recommended Fix

  1. Define expected schema using zod or joi
  2. Validate parsed JSON against schema before use
  3. Sanitize all string fields
  4. Implement allowlist of expected properties
  5. Add type checking for all fields

References


Found by Arcanum sec-context security review

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions