Skip to content

Add JSON validation for OCI API responses in get_instance_details() #91

@senomorf

Description

@senomorf

Security Enhancement: JSON Validation

Issue Description

The get_instance_details() function in scripts/notify.sh currently processes JSON responses from OCI API without validation, creating a potential command injection vulnerability.

Current Code (Lines 273-278)

id=$(echo "$instance_data" | jq -r '.id // "unknown"')
shape=$(echo "$instance_data" | jq -r '.shape // "unknown"') 
ad=$(echo "$instance_data" | jq -r '.ad // "unknown"' | sed 's/.*-AD-/AD-/')

Vulnerability

If instance_data contains malicious JSON, the sed command could be vulnerable to injection attacks.

Recommended Solution

Add JSON structure validation before processing:

# Validate JSON structure first
if ! echo "$instance_data" | jq -e . >/dev/null 2>&1; then
    log_error "Invalid JSON response from OCI API"
    return 1
fi

# Then proceed with safe parsing
id=$(echo "$instance_data" | jq -r '.id // "unknown"')
shape=$(echo "$instance_data" | jq -r '.shape // "unknown"') 
ad=$(echo "$instance_data" | jq -r '.ad // "unknown"' | sed 's/.*-AD-/AD-/')

Priority

High - Security vulnerability that should be addressed promptly.

Context

Identified in PR #89 code review by Claude Code automated review system.

Acceptance Criteria

  • Add JSON validation before parsing OCI API responses
  • Ensure graceful error handling if validation fails
  • Add appropriate logging for invalid JSON responses
  • Test with malformed JSON inputs to verify protection

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions