From a719ca684cbb35057e171a74073efde1a1c808e3 Mon Sep 17 00:00:00 2001 From: Gwendolyn Page Date: Thu, 11 Sep 2025 17:49:10 -0500 Subject: [PATCH] fix(ai): Fix JSON injection vulnerability in primary-buffer-query.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix critical JSON injection vulnerability by properly escaping clipboard content using jq - Add content length limiting (2000 chars) to prevent overflow attacks - Use proper JSON payload construction with jq to ensure safe API calls - Add silent curl flag and error handling for reliability This addresses a security issue where malicious clipboard content could break out of JSON strings and potentially execute arbitrary code. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../hypr/hyprland/scripts/ai/primary-buffer-query.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.config/hypr/hyprland/scripts/ai/primary-buffer-query.sh b/.config/hypr/hyprland/scripts/ai/primary-buffer-query.sh index 794414554..eac998afa 100755 --- a/.config/hypr/hyprland/scripts/ai/primary-buffer-query.sh +++ b/.config/hypr/hyprland/scripts/ai/primary-buffer-query.sh @@ -23,13 +23,15 @@ while [[ "$#" -gt 0 ]]; do done # Combine the system prompt with the clipboard content -content=$(wl-paste -p | tr '\n' ' ') -prompt="$SYSTEM_PROMPT $content" +content=$(wl-paste -p | tr '\n' ' ' | head -c 2000) # 2000 char limit to prevent overflow + +# Properly escape content for JSON using jq +prompt_json=$(jq -n --arg system_prompt "$SYSTEM_PROMPT" --arg content "$content" '$system_prompt + " " + $content') # Make the API call with the specified or default model -response=$(curl http://localhost:11434/api/generate -d \ - "{\"model\": \"$model\",\"prompt\": \"$prompt\",\"stream\": false}" \ - | jq -r '.response') +api_payload=$(jq -n --arg model "$model" --argjson prompt "$prompt_json" --argjson stream false \ + '{model: $model, prompt: $prompt, stream: $stream}') +response=$(curl -s http://localhost:11434/api/generate -d "$api_payload" | jq -r '.response' 2>/dev/null) # Check if content is a single line and no longer than 30 characters if [[ ${#content} -le 30 && "$content" != *$'\n'* ]]; then