v0.7.10 - Fixed api errors in accepting : in subscriptions
This commit is contained in:
@@ -32,27 +32,40 @@ test_sql_injection() {
|
||||
echo -n "Testing $description... "
|
||||
|
||||
# Send message via websocat and capture response
|
||||
# For now, we'll test without authentication since the relay may not require it for basic queries
|
||||
local response
|
||||
response=$(timeout 5 bash -c "
|
||||
echo '$message' | websocat -B 1048576 --no-close ws://$RELAY_HOST:$RELAY_PORT 2>/dev/null | head -3
|
||||
" 2>/dev/null || echo 'TIMEOUT')
|
||||
response=$(echo "$message" | timeout 2 websocat ws://$RELAY_HOST:$RELAY_PORT 2>/dev/null | head -1 || echo 'TIMEOUT')
|
||||
|
||||
# Check if the response indicates successful query execution (which would be bad)
|
||||
# Look for signs that SQL injection worked (like database errors or unexpected results)
|
||||
if [[ "$response" == *"SQL"* ]] || [[ "$response" == *"syntax"* ]] || [[ "$response" == *"error"* && ! "$response" == *"error: "* ]]; then
|
||||
echo -e "${RED}FAILED${NC} - Potential SQL injection vulnerability detected"
|
||||
echo " Response: $response"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
elif [[ "$response" == "TIMEOUT" ]]; then
|
||||
if [[ "$response" == "TIMEOUT" ]]; then
|
||||
echo -e "${YELLOW}UNCERTAIN${NC} - Connection timeout (may indicate crash)"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
else
|
||||
echo -e "${GREEN}PASSED${NC} - SQL injection blocked"
|
||||
elif [[ -z "$response" ]]; then
|
||||
# Empty response - relay silently rejected malformed input
|
||||
echo -e "${GREEN}PASSED${NC} - SQL injection blocked (silently rejected)"
|
||||
PASSED_TESTS=$((PASSED_TESTS + 1))
|
||||
return 0
|
||||
elif [[ "$response" == *"NOTICE"* ]] && [[ "$response" == *"error:"* ]]; then
|
||||
# Relay properly rejected the input with a NOTICE error message
|
||||
echo -e "${GREEN}PASSED${NC} - SQL injection blocked (rejected with error)"
|
||||
PASSED_TESTS=$((PASSED_TESTS + 1))
|
||||
return 0
|
||||
elif [[ "$response" == *"EOSE"* ]] || [[ "$response" == *"COUNT"* ]] || [[ "$response" == *"EVENT"* ]]; then
|
||||
# Query completed normally - this is expected for properly sanitized input
|
||||
echo -e "${GREEN}PASSED${NC} - SQL injection blocked (query sanitized)"
|
||||
PASSED_TESTS=$((PASSED_TESTS + 1))
|
||||
return 0
|
||||
elif [[ "$response" == *"SQL"* ]] || [[ "$response" == *"syntax"* ]]; then
|
||||
# Database error leaked - potential vulnerability
|
||||
echo -e "${RED}FAILED${NC} - SQL error leaked: $response"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
else
|
||||
# Unknown response
|
||||
echo -e "${YELLOW}UNCERTAIN${NC} - Unexpected response: $response"
|
||||
FAILED_TESTS=$((FAILED_TESTS + 1))
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -66,9 +79,7 @@ test_valid_query() {
|
||||
echo -n "Testing $description... "
|
||||
|
||||
local response
|
||||
response=$(timeout 5 bash -c "
|
||||
echo '$message' | websocat -B 1048576 --no-close ws://$RELAY_HOST:$RELAY_PORT 2>/dev/null | head -3
|
||||
" 2>/dev/null || echo 'TIMEOUT')
|
||||
response=$(echo "$message" | timeout 2 websocat ws://$RELAY_HOST:$RELAY_PORT 2>/dev/null | head -1 || echo 'TIMEOUT')
|
||||
|
||||
if [[ "$response" == *"EOSE"* ]] || [[ "$response" == *"EVENT"* ]]; then
|
||||
echo -e "${GREEN}PASSED${NC} - Valid query works"
|
||||
@@ -160,9 +171,10 @@ done
|
||||
echo
|
||||
|
||||
echo "=== Kinds Filter SQL Injection Tests ==="
|
||||
# Test numeric kinds with SQL injection
|
||||
test_sql_injection "Kinds filter with UNION injection" "[\"REQ\",\"sql_test_kinds_$RANDOM\",{\"kinds\":[0 UNION SELECT 1,2,3]}]"
|
||||
test_sql_injection "Kinds filter with stacked query" "[\"REQ\",\"sql_test_kinds_$RANDOM\",{\"kinds\":[0; DROP TABLE events; --]}]"
|
||||
# Test numeric kinds with SQL injection attempts (these will fail JSON parsing, which is expected)
|
||||
test_sql_injection "Kinds filter with string injection" "[\"REQ\",\"sql_test_kinds_$RANDOM\",{\"kinds\":[\"1' OR '1'='1\"]}]"
|
||||
test_sql_injection "Kinds filter with negative value" "[\"REQ\",\"sql_test_kinds_$RANDOM\",{\"kinds\":[-1]}]"
|
||||
test_sql_injection "Kinds filter with very large value" "[\"REQ\",\"sql_test_kinds_$RANDOM\",{\"kinds\":[999999999]}]"
|
||||
echo
|
||||
|
||||
echo "=== Search Filter SQL Injection Tests ==="
|
||||
|
||||
Reference in New Issue
Block a user