forked from Shinonome/dots-hyprland
fix(ai): Fix JSON injection vulnerability in primary-buffer-query.sh
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user