Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: add GitHub Action to detect unencrypted file writes

LearningCircuit962236b40d76
diff --git a/.github/workflows/security-file-write-check.yml b/.github/workflows/security-file-write-check.yml
new file mode 100644
index 0000000000..4af61d87d7
--- /dev/null
+++ b/.github/workflows/security-file-write-check.yml
@@ -0,0 +1,181 @@
+name: Security File Write Check
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened]
+ paths:
+ - '**/*.py'
+ - '**/*.js'
+ - '**/*.ts'
+ push:
+ branches:
+ - main
+ - dev
+ paths:
+ - '**/*.py'
+ - '**/*.js'
+ - '**/*.ts'
+
+jobs:
+ check-file-writes:
+ name: Check for Unencrypted File Writes
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Check for potential unencrypted file writes
+ run: |
+ echo "Checking for potential unencrypted file writes to disk..."
+ echo "========================================="
+
+ # Patterns that might indicate writing sensitive data to disk
+ SUSPICIOUS_PATTERNS=(
+ # Python patterns
+ "\.write\(.*\).*#.*(?!test|mock|stub)"
+ "\.save\(.*\).*#.*(?!test|mock|stub)"
+ "\.dump\(.*\).*#.*(?!test|mock|stub)"
+ "open\(.*['\"]w['\"]"
+ "open\(.*['\"]wb['\"]"
+ "\.to_csv\("
+ "\.to_json\("
+ "\.to_excel\("
+ "\.to_pickle\("
+ "tempfile\.NamedTemporaryFile.*delete=False"
+ "Path.*\.write_text\("
+ "Path.*\.write_bytes\("
+ "shutil\.copy"
+ "shutil\.move"
+ "\.export_to_file\("
+ "\.save_to_file\("
+ "\.write_pdf\("
+ "\.savefig\("
+ # JavaScript patterns
+ "fs\.writeFile"
+ "fs\.writeFileSync"
+ "fs\.createWriteStream"
+ "fs\.appendFile"
+ # Exclude certain directories
+ )
+
+ # Directories to exclude from checks
+ EXCLUDE_DIRS=(
+ "tests"
+ "test"
+ "__pycache__"
+ ".git"
+ "node_modules"
+ ".venv"
+ "venv"
+ "migrations"
+ "static/js/lib"
+ "static/vendor"
+ )
+
+ # Files to exclude
+ EXCLUDE_FILES=(
+ "*_test.py"
+ "test_*.py"
+ "*.test.js"
+ "*.spec.js"
+ "*.test.ts"
+ "*.spec.ts"
+ "setup.py"
+ "webpack.config.js"
+ "**/migrations/*.py"
+ )
+
+ # Build exclude arguments for grep
+ EXCLUDE_ARGS=""
+ for dir in "${EXCLUDE_DIRS[@]}"; do
+ EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude-dir=$dir"
+ done
+
+ for file in "${EXCLUDE_FILES[@]}"; do
+ EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude=$file"
+ done
+
+ # Track if we found any issues
+ FOUND_ISSUES=0
+
+ # Check each pattern
+ for pattern in "${SUSPICIOUS_PATTERNS[@]}"; do
+ echo "Checking pattern: $pattern"
+
+ # Use grep to find matches, but continue even if none found
+ matches=$(grep -rn "$pattern" . $EXCLUDE_ARGS --include="*.py" --include="*.js" --include="*.ts" 2>/dev/null || true)
+
+ if [ -n "$matches" ]; then
+ # Filter out false positives
+ filtered_matches=""
+ while IFS= read -r line; do
+ # Skip if line contains certain keywords that indicate it's safe
+ if ! echo "$line" | grep -qE "(encrypted|encrypt|cipher|test_|mock_|stub_|# Safe:|# OK:|# TODO: encrypt|\.encrypted|_encrypted|get_encrypted_|set_encrypted_|storage/database|storage/encrypted|web/services/pdf_service\.py|web/services/research_service\.py:.*export_report_to_memory)"; then
+ # Skip known safe usages (logs, configs that don't contain sensitive data)
+ if ! echo "$line" | grep -qE "(logger\.|logging\.|print\(|console\.log|debug|\.write\(['\"](Starting|Stopping|Error|Warning|Info)|config\.toml|settings\.toml|\.env\.template)"; then
+ filtered_matches="$filtered_matches$line\n"
+ fi
+ fi
+ done <<< "$matches"
+
+ if [ -n "$filtered_matches" ]; then
+ echo "⚠️ Found potential unencrypted file writes:"
+ echo -e "$filtered_matches"
+ FOUND_ISSUES=1
+ fi
+ fi
+ done
+
+ echo "========================================="
+
+ # Check for specific problematic patterns
+ echo "Checking for temp file usage without proper cleanup..."
+ temp_issues=$(grep -rn "get_report_as_temp_file\|tmp_path\|tempfile\|/tmp/" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null | grep -v "test" | grep -v "mock" | grep -v "# Safe:" || true)
+
+ if [ -n "$temp_issues" ]; then
+ echo "⚠️ Found temporary file usage that might leave unencrypted data:"
+ echo "$temp_issues"
+ FOUND_ISSUES=1
+ fi
+
+ echo "========================================="
+
+ # Check for direct database content writes to files
+ echo "Checking for database content being written to files..."
+ db_write_issues=$(grep -rn "report_content.*open\|report_content.*write\|markdown_content.*open\|markdown_content.*write" . $EXCLUDE_ARGS --include="*.py" 2>/dev/null | grep -v "test" | grep -v "mock" || true)
+
+ if [ -n "$db_write_issues" ]; then
+ echo "⚠️ Found database content being written to files:"
+ echo "$db_write_issues"
+ FOUND_ISSUES=1
+ fi
+
+ echo "========================================="
+
+ if [ $FOUND_ISSUES -eq 1 ]; then
+ echo "❌ Security check failed: Found potential unencrypted file writes"
+ echo ""
+ echo "Please review the above findings and ensure:"
+ echo "1. Sensitive data is not written to disk unencrypted"
+ echo "2. Temporary files are properly cleaned up"
+ echo "3. Use in-memory operations where possible"
+ echo "4. If file writes are necessary, ensure they're encrypted or add '# Safe: <reason>' comment"
+ echo ""
+ echo "For exports, use the in-memory pattern like in export_report_to_memory()"
+ exit 1
+ else
+ echo "✅ Security check passed: No suspicious unencrypted file writes detected"
+ fi
+
+ - name: Check for export patterns
+ run: |
+ echo "Checking for export methods that might bypass encryption..."
+
+ # Check if export methods are using in-memory patterns
+ if grep -rn "export.*Path\|export.*path\.open\|export.*\.write" . --include="*.py" | grep -v "test" | grep -v "export_report_to_memory" | grep -v "# Safe:"; then
+ echo "⚠️ Found export methods that might write to disk"
+ echo "Consider using in-memory patterns like export_report_to_memory()"
+ exit 1
+ fi
+
+ echo "✅ Export methods appear to use safe patterns"