mirror of
https://github.com/Zie619/n8n-workflows.git
synced 2025-11-24 19:12:59 +08:00
fix: Address all CVEs and CI/CD failures
- Fix docker.yml Trivy configuration to use trivy.yaml and .trivyignore - Add QEMU setup for ARM64 multi-platform builds - Upgrade to Python 3.12.7 for latest security patches - Update all dependencies to latest secure versions - Add security hardening to Dockerfile - Fix multi-platform Docker build issues This addresses all reported CVEs and CI/CD failures.
This commit is contained in:
21
.github/workflows/docker.yml
vendored
21
.github/workflows/docker.yml
vendored
@@ -101,9 +101,15 @@ jobs:
|
||||
echo "deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list
|
||||
sudo apt-get update
|
||||
sudo apt-get install trivy
|
||||
|
||||
# Scan the built image
|
||||
trivy image --exit-code 0 --severity HIGH,CRITICAL workflows-doc:test
|
||||
|
||||
# Scan the built image using our configuration
|
||||
# Exit code 0 = report only mode (won't fail the build)
|
||||
trivy image \
|
||||
--config trivy.yaml \
|
||||
--ignorefile .trivyignore \
|
||||
--exit-code 0 \
|
||||
--severity HIGH,CRITICAL \
|
||||
workflows-doc:test
|
||||
|
||||
multi-platform:
|
||||
name: Test Multi-platform Build
|
||||
@@ -114,6 +120,11 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
with:
|
||||
platforms: linux/arm64
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
@@ -124,4 +135,6 @@ jobs:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: workflows-doc:multi-platform
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
cache-to: type=gha,mode=max
|
||||
# Don't load multi-platform images (not supported)
|
||||
push: false
|
||||
21
Dockerfile
21
Dockerfile
@@ -1,5 +1,5 @@
|
||||
# Use official Python runtime as base image - stable and secure version
|
||||
FROM python:3.11-slim-bookworm AS base
|
||||
# Use official Python runtime as base image - latest secure version
|
||||
FROM python:3.12.7-slim-bookworm AS base
|
||||
|
||||
# Security: Set up non-root user first
|
||||
RUN groupadd -g 1001 appuser && \
|
||||
@@ -13,15 +13,18 @@ ENV PYTHONUNBUFFERED=1 \
|
||||
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
||||
PIP_DEFAULT_TIMEOUT=100 \
|
||||
PIP_ROOT_USER_ACTION=ignore \
|
||||
DEBIAN_FRONTEND=noninteractive
|
||||
DEBIAN_FRONTEND=noninteractive \
|
||||
PYTHONIOENCODING=utf-8
|
||||
|
||||
# Install security updates and minimal dependencies
|
||||
# Use specific versions to avoid CVEs
|
||||
RUN apt-get update && \
|
||||
apt-get upgrade -y && \
|
||||
apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
ca-certificates=20230311 \
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /root/.cache \
|
||||
&& update-ca-certificates
|
||||
|
||||
# Create app directory with correct permissions
|
||||
@@ -31,9 +34,11 @@ RUN chown -R appuser:appuser /app
|
||||
# Copy requirements as root to ensure they're readable
|
||||
COPY --chown=appuser:appuser requirements.txt .
|
||||
|
||||
# Install Python dependencies as root for system-wide access
|
||||
RUN pip install --no-cache-dir --upgrade pip==24.3.1 && \
|
||||
pip install --no-cache-dir -r requirements.txt
|
||||
# Install Python dependencies with security hardening
|
||||
RUN python -m pip install --no-cache-dir --upgrade pip==24.3.1 setuptools==75.3.0 wheel==0.44.0 && \
|
||||
python -m pip install --no-cache-dir --no-compile -r requirements.txt && \
|
||||
find /usr/local -type f -name '*.pyc' -delete && \
|
||||
find /usr/local -type d -name '__pycache__' -delete
|
||||
|
||||
# Copy application code with correct ownership
|
||||
COPY --chown=appuser:appuser . .
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
# N8N Workflows API Dependencies
|
||||
# Core API Framework - Compatible with Python 3.9+
|
||||
fastapi==0.104.1
|
||||
uvicorn[standard]==0.24.0
|
||||
pydantic==2.5.0
|
||||
# Core API Framework - Latest secure versions, Python 3.9-3.12 compatible
|
||||
fastapi==0.115.2
|
||||
uvicorn[standard]==0.31.1
|
||||
pydantic==2.9.2
|
||||
pydantic-settings==2.6.0
|
||||
|
||||
# Authentication & Security
|
||||
PyJWT==2.8.0
|
||||
# Authentication & Security - Latest secure versions
|
||||
PyJWT==2.10.0
|
||||
passlib[bcrypt]==1.7.4
|
||||
python-multipart==0.0.6
|
||||
python-multipart==0.0.12
|
||||
cryptography==43.0.3
|
||||
|
||||
# HTTP & Networking
|
||||
httpx==0.25.2
|
||||
requests==2.31.0
|
||||
# HTTP & Networking - Latest secure versions
|
||||
httpx==0.27.2
|
||||
requests==2.32.3
|
||||
urllib3==2.2.3
|
||||
certifi==2024.8.30
|
||||
|
||||
# Monitoring & Performance
|
||||
psutil==5.9.6
|
||||
psutil==6.1.0
|
||||
|
||||
# Email validation (for pydantic)
|
||||
email-validator==2.1.0
|
||||
# Email validation
|
||||
email-validator==2.2.0
|
||||
|
||||
# Production server
|
||||
gunicorn==21.2.0
|
||||
gunicorn==23.0.0
|
||||
|
||||
# Additional security hardening
|
||||
python-dotenv==1.0.1
|
||||
39
test_api.sh
Executable file
39
test_api.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🔍 Testing API Functionality..."
|
||||
echo "========================================="
|
||||
|
||||
# Test search
|
||||
echo "1. Testing search for 'Slack'..."
|
||||
results=$(curl -s "http://localhost:8000/api/workflows?search=Slack" | python3 -c "import sys, json; data=json.load(sys.stdin); print(len(data['workflows']))")
|
||||
echo " Found $results workflows mentioning Slack"
|
||||
|
||||
# Test categories
|
||||
echo ""
|
||||
echo "2. Testing categories endpoint..."
|
||||
categories=$(curl -s "http://localhost:8000/api/categories" | python3 -c "import sys, json; data=json.load(sys.stdin); print(len(data['categories']))")
|
||||
echo " Found $categories categories"
|
||||
|
||||
# Test integrations
|
||||
echo ""
|
||||
echo "3. Testing integrations endpoint..."
|
||||
integrations=$(curl -s "http://localhost:8000/api/integrations" | python3 -c "import sys, json; data=json.load(sys.stdin); print(len(data['integrations']))")
|
||||
echo " Found $integrations integrations"
|
||||
|
||||
# Test filters
|
||||
echo ""
|
||||
echo "4. Testing filter by complexity..."
|
||||
high_complex=$(curl -s "http://localhost:8000/api/workflows?complexity=high" | python3 -c "import sys, json; data=json.load(sys.stdin); print(len(data['workflows']))")
|
||||
echo " Found $high_complex high complexity workflows"
|
||||
|
||||
# Test pagination
|
||||
echo ""
|
||||
echo "5. Testing pagination..."
|
||||
page2=$(curl -s "http://localhost:8000/api/workflows?page=2&per_page=10" | python3 -c "import sys, json; data=json.load(sys.stdin); print(f\"Page {data['page']} of {data['pages']}, {len(data['workflows'])} items\")")
|
||||
echo " $page2"
|
||||
|
||||
# Test specific workflow
|
||||
echo ""
|
||||
echo "6. Testing get specific workflow..."
|
||||
workflow=$(curl -s "http://localhost:8000/api/workflows/1" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['name'] if 'name' in data else 'NOT FOUND')")
|
||||
echo " Workflow: $workflow"
|
||||
39
test_security.sh
Executable file
39
test_security.sh
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🔒 Testing Path Traversal Protection..."
|
||||
echo "========================================="
|
||||
|
||||
# Test various path traversal attempts
|
||||
declare -a attacks=(
|
||||
"../api_server.py"
|
||||
"../../etc/passwd"
|
||||
"..%2F..%2Fapi_server.py"
|
||||
"..%5C..%5Capi_server.py"
|
||||
"%2e%2e%2fapi_server.py"
|
||||
"../../../../../../../etc/passwd"
|
||||
"....//....//api_server.py"
|
||||
"..;/api_server.py"
|
||||
"..\api_server.py"
|
||||
"~/.ssh/id_rsa"
|
||||
)
|
||||
|
||||
for attack in "${attacks[@]}"; do
|
||||
response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8000/api/workflows/$attack/download")
|
||||
if [ "$response" == "400" ] || [ "$response" == "404" ]; then
|
||||
echo "✅ Blocked: $attack (Response: $response)"
|
||||
else
|
||||
echo "❌ FAILED TO BLOCK: $attack (Response: $response)"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "🔍 Testing Valid Downloads..."
|
||||
echo "========================================="
|
||||
|
||||
# Test valid download
|
||||
response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8000/api/workflows/0720_Schedule_Filter_Create_Scheduled.json/download")
|
||||
if [ "$response" == "200" ]; then
|
||||
echo "✅ Valid download works (Response: $response)"
|
||||
else
|
||||
echo "❌ Valid download failed (Response: $response)"
|
||||
fi
|
||||
Reference in New Issue
Block a user