feat: integrate rate limiting and enhance security features

- Added @convex-dev/rate-limiter dependency to manage request limits effectively.
- Implemented rate limiting configurations for IPs, users, and endpoints to prevent abuse and enhance security.
- Introduced new security analysis endpoint to detect potential attacks based on incoming requests.
- Updated backend schema to include rate limit configurations and various cyber attack types for improved incident tracking.
- Enhanced existing security functions to incorporate rate limiting checks, ensuring robust protection against brute force and other attacks.
This commit is contained in:
2025-11-16 01:20:57 -03:00
parent ea01e2401a
commit 88983ea297
19 changed files with 3102 additions and 109 deletions

78
scripts/teste_rapido.sh Executable file
View File

@@ -0,0 +1,78 @@
#!/bin/bash
# Script rápido para executar testes de segurança no SGSE
# Uso: ./teste_rapido.sh [tipo_teste]
echo "🛡️ Teste de Segurança SGSE - Execução Rápida"
echo ""
# Obter diretório do script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VENV_DIR="$SCRIPT_DIR/venv_seguranca"
# Verificar se Python está instalado
if ! command -v python3 &> /dev/null; then
echo "❌ Python 3 não encontrado. Por favor, instale Python 3.8+"
exit 1
fi
# Criar ambiente virtual se não existir
if [ ! -d "$VENV_DIR" ]; then
echo "📦 Criando ambiente virtual..."
cd "$SCRIPT_DIR"
python3 -m venv venv_seguranca
source venv_seguranca/bin/activate
pip install requests > /dev/null 2>&1
echo "✅ Ambiente virtual criado e dependências instaladas"
else
# Ativar ambiente virtual
source "$VENV_DIR/bin/activate"
fi
# Verificar se requests está instalado
if ! python3 -c "import requests" 2>/dev/null; then
echo "⚠️ Biblioteca 'requests' não encontrada. Instalando..."
pip install requests
fi
# Tipo de teste (padrão: todos)
TIPO_TESTE=${1:-todos}
# URL base (pode ser alterada via variável de ambiente)
URL_BASE=${SGSE_URL:-http://localhost:5173}
CONVEX_URL=${CONVEX_URL:-http://127.0.0.1:3210}
echo "📍 URL Base: $URL_BASE"
echo "📍 Convex URL: $CONVEX_URL"
echo ""
# Executar teste
case $TIPO_TESTE in
brute_force|sql_injection|xss|ddos|path_traversal|command_injection|nosql|xxe)
echo "🔍 Executando teste: $TIPO_TESTE"
python3 "$SCRIPT_DIR/teste_seguranca.py" --url "$URL_BASE" --convex-url "$CONVEX_URL" --teste "$TIPO_TESTE"
;;
todos)
echo "🔍 Executando TODOS os testes..."
python3 "$SCRIPT_DIR/teste_seguranca.py" --url "$URL_BASE" --convex-url "$CONVEX_URL"
;;
*)
echo "❌ Tipo de teste inválido: $TIPO_TESTE"
echo ""
echo "Tipos disponíveis:"
echo " - brute_force"
echo " - sql_injection"
echo " - xss"
echo " - ddos"
echo " - path_traversal"
echo " - command_injection"
echo " - nosql"
echo " - xxe"
echo " - todos (padrão)"
exit 1
;;
esac
echo ""
echo "✅ Teste concluído!"