-
-
Notifications
You must be signed in to change notification settings - Fork 2
REMEDIATION_SUMMARY
Status: 🔴 IN PROGRESS (0% Complete) Priority: CRITICAL Total Vulnerabilities: ~150 Estimated Effort: 60-80 hours
| Phase | Files | Vulnerabilities | Status | Due Date |
|---|---|---|---|---|
| Phase 1 | 2 files | 60 critical | 🔴 Not Started | Week 1 |
| Phase 2 | 3 files | 90 remaining | 🔴 Not Started | Week 2 |
| Phase 3 | Testing | N/A | 🔴 Not Started | Week 3 |
- ✅ Start here:
SQL_INJECTION_REMEDIATION_REPORT.md - ✅ Fix guide:
SQL_INJECTION_FIX_GUIDE.md - ✅ This summary: Quick reference
# Source validation functions
source src/lib/utils/validation.sh
# Source safe query functions
source src/lib/database/safe-query.sh
# Run existing tests
bash src/tests/security/test-sql-injection.sh# File 1: billing/usage.sh (60 vulnerabilities)
# File 2: billing/reports.sh (30 vulnerabilities)
# For each function:
# 1. Add input validation
# 2. Replace ${var} with :'param'
# 3. Add parameters to billing_db_query call
# 4. Test manually
# 5. Commit1. Usage Aggregate Functions (billing/usage.sh)
- Lines: 305-312, 350-357, 839-924
- Impact: Financial data exposure
- Difficulty: Medium
- Time: 4 hours
2. Tenant Provisioning (tenant/lifecycle.sh)
- Lines: 34-79
- Impact: Account takeover, privilege escalation
- Difficulty: Hard
- Time: 3 hours
3. Usage Export (billing/usage.sh)
- Lines: 1195-1310
- Impact: Complete data exfiltration
- Difficulty: Hard (dynamic WHERE clauses)
- Time: 3 hours
# Validate
validate_uuid "$id" || return 1
# Parameterize
billing_db_query "SELECT * FROM table WHERE id = :'id'" "tuples" "id" "$id"# Validate all
validate_uuid "$customer_id" || return 1
validate_service_name "$service" || return 1
# Parameterize all
billing_db_query "
SELECT * FROM table
WHERE customer_id = :'customer_id'
AND service = :'service'
" "tuples" "customer_id" "$customer_id" "service" "$service"# Use COALESCE or conditional SQL
billing_db_query "
SELECT * FROM table
WHERE customer_id = :'customer_id'
AND (:'service' = '' OR service = :'service')
AND (:'start_date' = '' OR date >= :'start_date'::timestamp)
" "tuples" \
"customer_id" "$customer_id" \
"service" "${service:-}" \
"start_date" "${start_date:-}"# Search for string interpolation in SQL
grep -rn "WHERE.*'\${" src/lib/billing/
grep -rn "WHERE.*'\${" src/lib/tenant/
# Search for unparameterized psql calls
grep -rn "psql.*-c.*\"\$" src/lib/tenant/
# Search for unsafe billing_db_query calls
grep -rn "billing_db_query.*'\${" src/lib/billing/# Pattern 1: Single WHERE clause
FROM: WHERE id = '${id}'
TO: WHERE id = :'id'
ADD: "id" "$id" to billing_db_query parameters
# Pattern 2: Multiple WHERE clauses
FROM: WHERE a = '${a}' AND b = '${b}'
TO: WHERE a = :'a' AND b = :'b'
ADD: "a" "$a" "b" "$b" to parameters
# Pattern 3: Dynamic WHERE
FROM: where_clause="customer_id = '${customer_id}'"
TO: (Delete variable, use SQL conditional instead)
WHERE customer_id = :'customer_id'
AND (:'optional' = '' OR field = :'optional')For each fixed function:
# 1. Validation test
result=$(function_name "'; DROP TABLE users; --" 2>&1)
# Should: Error "Invalid format"
# 2. Normal operation test
result=$(function_name "valid-value")
# Should: Work correctly
# 3. Special characters test
result=$(function_name "test@example.com")
# Should: Work correctly (chars treated as literals)
# 4. Edge case test
result=$(function_name "")
# Should: Error "Invalid format"- src/lib/billing/usage.sh (0/60 vulnerabilities)
- src/lib/billing/reports.sh (0/30 vulnerabilities)
- src/lib/tenant/lifecycle.sh (0/25 vulnerabilities)
- src/lib/tenant/core.sh (0/20 vulnerabilities)
- src/lib/tenant/routing.sh (0/15 vulnerabilities)
Billing - Usage (0/13)
- usage_get_all_table()
- usage_get_service_table()
- usage_get_all_json()
- usage_get_all_csv()
- usage_get_service_json()
- usage_get_service_csv()
- usage_aggregate_hourly()
- usage_aggregate_daily()
- usage_aggregate_monthly()
- usage_check_service_alert()
- usage_export_csv()
- usage_export_json()
- usage_get_peaks()
Billing - Reports (0/5)
- report_usage_trends_table()
- report_usage_trends_csv()
- report_usage_trends_json()
- report_churn_table()
- report_aging_table()
Tenant - Lifecycle (0/10)
- tenant_provision()
- create_tenant_owner()
- initialize_tenant_settings()
- tenant_lifecycle_suspend()
- tenant_lifecycle_activate()
- tenant_soft_delete()
- tenant_permanent_delete()
- tenant_migrate_plan()
- tenant_create_backup()
- tenant_health_check()
Tenant - Core (0/7)
- tenant_list()
- tenant_show()
- tenant_suspend()
- tenant_activate()
- tenant_member_remove()
- tenant_member_list()
- tenant_domain_add()
Tenant - Routing (0/2)
- generate_custom_domain_ssl()
- get_tenant_url()
- Fix usage_get_all_table() - 1 hour
- Fix usage_get_service_table() - 1 hour
- Fix usage_aggregate_hourly() - 1.5 hours
- Fix usage_aggregate_daily() - 1.5 hours
- Fix usage_aggregate_monthly() - 1.5 hours
- Test all fixes - 1.5 hours
Target: 5 functions, ~15 vulnerabilities fixed
- Fix usage_export_csv() - 2 hours
- Fix usage_export_json() - 1.5 hours
- Fix usage_get_peaks() - 1 hour
- Fix usage_check_service_alert() - 1.5 hours
- Test all fixes - 2 hours
Target: 4 functions, ~20 vulnerabilities fixed
- Fix tenant_provision() - 3 hours
- Fix tenant_lifecycle_suspend() - 1 hour
- Fix tenant_lifecycle_activate() - 1 hour
- Fix tenant_soft_delete() - 1 hour
- Test all fixes - 2 hours
Target: 4 functions, ~20 vulnerabilities fixed
- Validation functions:
src/lib/utils/validation.sh - Safe query functions:
src/lib/database/safe-query.sh - Working examples:
src/lib/billing/quotas.sh(already fixed) - Test framework:
src/tests/security/test-sql-injection.sh
- OWASP SQL Injection: https://owasp.org/www-community/attacks/SQL_Injection
- PostgreSQL Prepared Statements: https://www.postgresql.org/docs/current/sql-prepare.html
- Input Validation Guide: https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html
# Find all string interpolation in SQL
rg "'\\\${" src/lib/billing/ src/lib/tenant/
# Find all unvalidated psql calls
rg "psql.*-c.*'\\\$" src/lib/
# Find all billing_db_query without parameters
rg "billing_db_query.*'\\\${" src/lib/billing/# Run all security tests
bash src/tests/security/test-sql-injection.sh
# Run specific function test
bash src/tests/security/test-usage-functions.sh usage_get_all_table
# Manual injection test
result=$(usage_get_all_table "'; DROP TABLE billing_usage_records; --" 2>&1)
echo "$result" | grep -q "Invalid" && echo "PASS" || echo "FAIL"# Good commit message format
git commit -m "security: fix SQL injection in usage_get_all_table()
- Add customer_id validation
- Parameterize all WHERE clause variables
- Replace string interpolation with :param syntax
- Add test for injection attempt
Fixes: #XXX (SQL Injection in billing module)
"-
❌ Forgetting Validation
# WRONG billing_db_query "WHERE id = :'id'" "tuples" "id" "$user_input" # RIGHT validate_uuid "$user_input" || return 1 billing_db_query "WHERE id = :'id'" "tuples" "id" "$user_input"
-
❌ Partial Parameterization
# WRONG - service is still vulnerable billing_db_query "WHERE id = :'id' AND service = '${service}'" "tuples" "id" "$id" # RIGHT billing_db_query "WHERE id = :'id' AND service = :'service'" "tuples" "id" "$id" "service" "$service"
-
❌ Building SQL Fragments
# WRONG filter="AND status = '${status}'" billing_db_query "SELECT * FROM table WHERE id = :'id' ${filter}" "tuples" "id" "$id" # RIGHT billing_db_query " SELECT * FROM table WHERE id = :'id' AND (:'status' = '' OR status = :'status') " "tuples" "id" "$id" "status" "${status:-}"
If stuck on a particularly complex vulnerability:
- Review the fix guide for similar patterns
- Check
src/lib/billing/quotas.shfor working examples - Search for existing safe implementations in codebase
- Ask for code review before committing
Remember: Better to ask for help than to commit an incorrect fix!
Before considering remediation complete:
- All 150 vulnerabilities fixed and tested
- All validation functions in place
- All queries use parameterized syntax
- No string interpolation in SQL strings
- All tests passing (including new security tests)
- Code review completed
- Documentation updated
- CI/CD includes SQL injection tests
- Production deployment blocked until complete
Next Steps: Start with Day 1 goals, fix first 5 functions, get code review.
Estimated Completion: 3 weeks (15 working days at 8 hours/day)
Last Updated: 2026-01-31 Progress: 0% (0/150 vulnerabilities fixed)
ɳSelf CLI v1.0.9. MIT licensed. Docs CC BY 4.0.
GitHub · Issues · Discussions · nself.org · nself.org/docs
Getting Started
Commands
- Commands, Overview
- Lifecycle: cmd-init · cmd-build · cmd-start · cmd-stop · cmd-restart · cmd-dev
- Monitoring: cmd-status · cmd-logs · cmd-health · cmd-urls · cmd-doctor · cmd-monitor · cmd-alerts · cmd-sentry · cmd-watchdog
- Data: cmd-db · cmd-backup · cmd-dr · cmd-queue · cmd-webhooks
- Config: cmd-config · cmd-service · cmd-env · cmd-promote
- Networking: cmd-ssl · cmd-trust · cmd-dns-setup
- Security: cmd-access · cmd-security · cmd-secrets
- Tenancy: cmd-tenant · cmd-billing
- Plugins: cmd-plugin · cmd-license · cmd-dogfood (extracted, CLI-R11) · cmd-k8s (extracted, CLI-R11) · cmd-encryption (extracted, CLI-R11) · cmd-waf (extracted, CLI-R11) · cmd-federation (extracted, CLI-R11) · cmd-mail (extracted, CLI-R11) · cmd-dlq (extracted, CLI-R11)
- AI: cmd-ai · cmd-claw · cmd-model
- Templates: cmd-template
- Utilities: cmd-exec · cmd-clean · cmd-reset · cmd-update · cmd-upgrade · cmd-version · cmd-admin · cmd-migrate · cmd-migrate-firebase · cmd-migrate-supabase · cmd-completion
Features
- Features, Overview
- Feature-Auth
- Feature-Storage
- Feature-Search
- Feature-Functions
- Feature-Email
- Feature-Monitoring
- Feature-Plugins
- Feature-nClaw, AI Assistant
- Feature-nChat, Messaging
- Feature-nTV, Media Player
- Feature-nFamily, Family Social
- Feature-nCloud, Managed Hosting
- Feature-Memory-Rooms, Knowledge Organization
- Feature-Agent-Dashboard, Agent Metrics
- Feature-Image-Generation, AI Image Generation
Configuration
- Configuration, Overview
- Config-Env-Vars
- Config-Postgres
- Config-Hasura
- Config-Auth
- Config-Nginx
- Config-Optional-Services
- Config-Custom-Services
- Config-System
Plugins (87 + 10 monitoring)
Free (25)
- plugin-backup
- plugin-content-acquisition
- plugin-content-progress
- plugin-cron
- plugin-donorbox
- plugin-feature-flags
- plugin-github
- plugin-github-runner
- plugin-invitations
- plugin-jobs
- plugin-link-preview
- plugin-mdns
- plugin-mlflow
- plugin-monitoring
- plugin-notifications
- plugin-notify
- plugin-paypal
- plugin-search
- plugin-shopify
- plugin-stripe
- plugin-subtitle-manager
- plugin-tokens
- plugin-torrent-manager
- plugin-vpn
- plugin-webhooks
Pro (62)
- plugin-access-controls
- plugin-activity-feed
- plugin-admin-api
- plugin-nself-ai-gateway
- plugin-nself-ai-mcp
- plugin-nself-ai-mcp
- plugin-analytics
- plugin-auth
- plugin-backup-pro
- plugin-bots
- plugin-browser
- plugin-calendar
- plugin-cdn
- plugin-chat
- plugin-claw
- plugin-claw-budget
- plugin-claw-news
- plugin-claw-web
- plugin-cloudflare
- plugin-cms
- plugin-compliance
- plugin-cron-pro
- plugin-ddns
- plugin-devices
- plugin-documents
- plugin-donorbox-pro
- plugin-entitlements
- plugin-epg
- plugin-file-processing
- plugin-game-metadata
- plugin-geocoding
- plugin-geolocation
- plugin-google
- plugin-home
- plugin-idme
- plugin-knowledge-base
- plugin-linkedin
- plugin-livekit
- plugin-media-processing
- plugin-meetings
- plugin-moderation
- plugin-mux
- plugin-notify-pro
- plugin-object-storage
- plugin-observability
- plugin-paypal-pro
- plugin-photos
- plugin-podcast
- plugin-post
- plugin-realtime
- plugin-recording
- plugin-retro-gaming
- plugin-rom-discovery
- plugin-shopify-pro
- plugin-social
- plugin-sports
- plugin-stream-gateway
- plugin-streaming
- plugin-stripe-pro
- plugin-support
- plugin-tmdb
- plugin-voice
- plugin-web3
- plugin-workflows
Planned (26)
plugin-auditplugin-blogplugin-checkoutplugin-commerceplugin-drmplugin-exportplugin-flowplugin-importplugin-ldapplugin-mailgunplugin-mediaplugin-oauth-providersplugin-pagesplugin-postmarkplugin-rate-limitplugin-reportsplugin-samlplugin-schedulerplugin-sendgridplugin-ssoplugin-subscriptionplugin-thumbplugin-transcoderplugin-twilioplugin-wafplugin-watermark
Guides
- Guide-Production-Deployment
- Guide-SSL-Setup
- Guide-Multi-Tenancy
- Guide-Security-Hardening
- Guide-Monitoring-Setup
- Guide-Backup-Restore
- Guide-Custom-Services
- Guide-Migration-from-v1
Architecture
Reference
- API-Reference
- error-codes, Error Codes
Licensing
Security
Brand
Operations
- operations/release-cascade, Release Cascade
- operations/self-healing, Self-Healing Schema
- operations/redis-tuning, Redis Pool Tuning
- operations/meilisearch-warmup, MeiliSearch Warm-Up
- operations/jwt-rotation, JWT Key Rotation
- operations/windows-wsl2-setup, Windows / WSL2 Setup
- operations/gemini-oauth-reauth, Gemini OAuth Reauth
Contributing
Admin
- USER-ACTION-QUEUE, Pending Admin Actions
All commands (52)
- A: cmd-access · cmd-account · cmd-admin
- B: cmd-backup · cmd-build · cmd-bundle
- C: cmd-ci · cmd-clean · cmd-completion · cmd-config
- D: cmd-db · cmd-deploy · cmd-dev · cmd-doctor
- E: cmd-env · cmd-exec
- F: cmd-functions
- G: cmd-generate
- H: cmd-health · cmd-help-topics
- I: cmd-init · cmd-install
- L: cmd-license · cmd-login · cmd-logout · cmd-logs
- M: cmd-man · cmd-mcp · cmd-migrate
- O: cmd-oauth · cmd-ops
- P: cmd-plugin · cmd-promote
- R: cmd-remove · cmd-reset · cmd-restart · cmd-runner
- S: cmd-secrets · cmd-security · cmd-self-heal · cmd-server · cmd-service · cmd-start · cmd-status · cmd-stop
- T: cmd-telemetry · cmd-template · cmd-trust
- U: cmd-update · cmd-urls
- V: cmd-verify-sbom · cmd-version