fix(ai): Fix JSON injection vulnerability in primary-buffer-query.sh (#1973)

This commit is contained in:
end-4
2025-09-21 20:04:15 +02:00
committed by GitHub
@@ -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