@echo off setlocal enabledelayedexpansion chcp 65001 >nul set PYTHONUTF8=1 set PYTHONIOENCODING=utf-8 echo ====================================================================== echo EDU-SPACE: AUTOMATED SECURITY AUDIT AND QA SUITE echo ====================================================================== echo. set ROOT_DIR=%~dp0 set VENV_PY=%ROOT_DIR%backend\venv\Scripts\python.exe set VENV_BANDIT=%ROOT_DIR%backend\venv\Scripts\bandit.exe set VENV_PIPAUDIT=%ROOT_DIR%backend\venv\Scripts\pip-audit.exe set VENV_ST=%ROOT_DIR%backend\venv\Scripts\st.exe set VENV_NJSSCAN=%ROOT_DIR%backend\venv\Scripts\njsscan.exe set OVERALL_STATUS=0 echo [1/6] Running Python SAST Analysis (Bandit)... echo ---------------------------------------------------------------------- if exist "%VENV_BANDIT%" ( call "%VENV_BANDIT%" -r "%ROOT_DIR%backend\app" "%ROOT_DIR%backend\routers" "%ROOT_DIR%backend\mcp_server.py" "%ROOT_DIR%backend\main.py" -ll -ii if !ERRORLEVEL! neq 0 ( echo [!] Warning: Bandit reported potential security concerns. set OVERALL_STATUS=1 ) else ( echo [OK] Bandit scan completed cleanly - 0 Medium/High issues. ) ) else ( echo [!] Error: Bandit executable not found at "%VENV_BANDIT%". set OVERALL_STATUS=1 ) echo. echo [2/6] Running Python SCA Dependency Audit (pip-audit)... echo ---------------------------------------------------------------------- if exist "%VENV_PIPAUDIT%" ( call "%VENV_PIPAUDIT%" -s osv --progress-spinner off -r "%ROOT_DIR%backend\requirements.txt" if !ERRORLEVEL! neq 0 ( echo [i] OSV feed unreachable or returned errors. Retrying with PyPI vulnerability service... call "%VENV_PIPAUDIT%" -s pypi --progress-spinner off -r "%ROOT_DIR%backend\requirements.txt" ) if !ERRORLEVEL! neq 0 ( echo [!] Warning: pip-audit reported package vulnerabilities or service unavailable. set OVERALL_STATUS=1 ) else ( echo [OK] All Python dependencies are secure - 0 known CVEs. ) ) else ( echo [!] Error: pip-audit executable not found at "%VENV_PIPAUDIT%". set OVERALL_STATUS=1 ) echo. echo [3/6] Running Node.js SAST Analysis (njsscan)... echo ---------------------------------------------------------------------- if exist "%VENV_NJSSCAN%" ( call "%VENV_NJSSCAN%" "%ROOT_DIR%frontend\src" if !ERRORLEVEL! neq 0 ( echo [!] Warning: njsscan reported code smells or security concerns. set OVERALL_STATUS=1 ) else ( echo [OK] Node.js SAST analysis completed cleanly. ) ) else ( echo [!] Error: njsscan executable not found at "%VENV_NJSSCAN%". set OVERALL_STATUS=1 ) echo. echo [4/6] Running Node.js SCA Dependency Audit (npm audit)... echo ---------------------------------------------------------------------- cd /d "%ROOT_DIR%frontend" call cmd.exe /c npm audit --audit-level=high if !ERRORLEVEL! neq 0 ( echo [!] Warning: npm audit reported package vulnerabilities. set OVERALL_STATUS=1 ) else ( echo [OK] All Node.js dependencies are secure - 0 High/Critical vulnerabilities. ) cd /d "%ROOT_DIR%" echo. echo [5/6] Running Dynamic API Security Fuzzing (Schemathesis DAST)... echo ---------------------------------------------------------------------- set API_DOC_URL=http://127.0.0.1:5000/openapi.json echo Checking backend availability at %API_DOC_URL%... curl.exe -s -f -o nul "%API_DOC_URL%" if !ERRORLEVEL! neq 0 ( echo Checking fallback at http://127.0.0.1:5000/api/v1/openapi.json... curl.exe -s -f -o nul "http://127.0.0.1:5000/api/v1/openapi.json" if !ERRORLEVEL! equ 0 ( set API_DOC_URL=http://127.0.0.1:5000/api/v1/openapi.json ) ) if !ERRORLEVEL! neq 0 ( echo [!] Note: Local FastAPI backend is not running on %API_DOC_URL% echo DAST live fuzzing requires live Uvicorn server. echo Skipping live DAST fuzzing - static contract validation preserved. ) else ( echo Target online. Running Schemathesis against OpenAPI spec... call "%VENV_ST%" run "%API_DOC_URL%" --checks not_a_server_error --max-examples=10 --no-color if !ERRORLEVEL! neq 0 ( echo [!] Warning: Schemathesis identified potential unhandled edge cases or server errors. set OVERALL_STATUS=1 ) else ( echo [OK] API DAST fuzzing passed - 0 unhandled 500 server errors. ) ) echo. echo [6/6] Running Security QA and Anti-Prompt Injection Test Suite... echo ---------------------------------------------------------------------- cd /d "%ROOT_DIR%backend" call "%VENV_PY%" -m pytest tests/test_prompt_security.py tests/test_mcp_and_walkthrough.py -v if !ERRORLEVEL! neq 0 ( echo [!] Error: Security and Anti-Prompt Injection tests failed. set OVERALL_STATUS=1 ) else ( echo [OK] Security QA Suite Passed - Anti-Prompt Injection, Guardrails and MCP 100%% verified. ) cd /d "%ROOT_DIR%" echo. echo ====================================================================== if %OVERALL_STATUS% equ 0 ( echo SECURITY AUDIT SUITE COMPLETED SUCCESSFULLY [PASS] ) else ( echo SECURITY AUDIT SUITE COMPLETED WITH WARNINGS [CHECK] ) echo ====================================================================== echo. if /I not "%~1"=="--no-pause" if /I not "%~1"=="-n" pause