This document outlines security best practices for developing, deploying, and maintaining the Tokenized Fractional RWA Marketplace. It covers secure development guidelines, common vulnerabilities, an audit checklist, incident response procedures, and security monitoring.
- Secure Development Guidelines
- Common Vulnerabilities and Mitigations
- Security Audit Checklist
- Incident Response Process
- Security Monitoring
- Least Privilege: Code and services should run with the minimum permissions necessary.
- Defense in Depth: Layer security controls so that a single failure does not compromise the system.
- Secure Defaults: Features should be secure by default; opt-in for less secure configurations.
- Fail Securely: Errors should default to denying access rather than granting it.
- Input Validation: Validate, sanitize, and encode all input at every layer.
- Use
soroban_sdkbuilt-in checks for authorization (require_auth). - Validate all function arguments (boundaries, zero values, overflow potential).
- Implement a circuit breaker / pause mechanism for emergency stops.
- Test with property-based testing (
proptest) in addition to unit tests. - Run
cargo auditbefore every release to check for dependency vulnerabilities. - Keep contract logic deterministic; avoid external calls that could introduce reentrancy.
- Keep dependencies updated: run
npm auditandnpx npm-check-updatesregularly. - Use
helmetmiddleware to set security headers (already configured). - Apply strict rate limiting on all endpoints (already configured per-IP and per-key).
- Validate and sanitize all request bodies and query parameters.
- Do not log sensitive data (API keys, tokens, personal information).
- Use environment variables for secrets; never hardcode or commit them.
- Set secure cookie flags (
HttpOnly,Secure,SameSite). - Enable Sentry for error monitoring and alerting (configured via
SENTRY_DSN).
- Sanitize any HTML rendered from user input to prevent XSS.
- Use Content Security Policy (CSP) headers (configure in nginx or Vite).
- Validate all environment variable inputs at build time.
- Never expose API keys or secrets in client-side code.
- Use
react-helmet-asyncor similar to manage<head>security concerns.
| Vulnerability | Risk | Mitigation |
|---|---|---|
| Reentrancy | Smart contract funds drained | Use checks-effects-interactions pattern; Soroban's require_auth provides protection |
| Integer Overflow/Underflow | Incorrect share calculations | Use checked_* arithmetic or saturating math |
| Unauthorized Admin Access | Contract takeover | Use require_auth with admin address; rotate keys regularly |
| XSS (Cross-Site Scripting) | User session hijacking | CSP headers; input sanitization; React auto-escaping |
| CSRF (Cross-Site Request Forgery) | Unauthorized state changes | SameSite cookies; CSRF tokens for any cookie-based auth |
| SQL Injection | Data breach | Use parameterized queries / ORM; the backend uses file-based storage (no SQL) |
| Path Traversal | Arbitrary file read | Validate file paths; restrict to data directory |
| SSRF (Server-Side Request Forgery) | Internal network probing | Validate and restrict outbound URLs; use an allow-list for webhook URLs |
| Insecure Direct Object Reference | Access other users' data | Use authentication checks before returning data |
| Dependency Vulnerabilities | Supply chain attacks | Regular npm audit / cargo audit; use lockfiles |
| Misconfigured CORS | Cross-origin data theft | Restrict origins to known frontend URLs (already configured) |
- Smart contract source code reviewed by at least one other developer
- All
admin-only functions protected withrequire_auth - Input boundaries tested (max share amounts, zero values, negative values)
-
cargo auditandnpm auditpass with no critical vulnerabilities - Environment variables reviewed — no secrets committed to repository
-
.env.exampledoes not contain real secrets - CORS origins configured to match the deployed frontend domain
- Rate limiting configured and tested
- Security headers verified (via securityheaders.com)
- HTTPS configured with valid certificate
- Logging level set to
infoorwarnin production (notdebug) - Sentry DSN configured and error reporting verified
- All endpoints tested with invalid/malformed inputs
- Rate limiting triggers correctly under load
- Webhook URLs validated — no SSRF exposure
- Static analysis tools run (ESLint, Clippy)
- Penetration test performed (or automated scanner run)
- SSL/TLS certificate valid and auto-renewal working
- Backup and restore procedures tested
- Dependencies updated for security patches
- Access logs reviewed for suspicious activity
- Failed authentication attempts reviewed
- Smart contract upgrade considered if vulnerabilities discovered
- Incident response plan reviewed and updated
Monitor for security incidents via:
- Application logs (ELK stack — Elasticsearch, Logstash, Kibana)
- Sentry error tracking
- Prometheus alerting rules
- Grafana dashboard anomalies
- Rate limit threshold alerts
When an incident is detected:
- Acknowledge: Respond within 1 hour (critical) or 4 hours (high).
- Assess: Determine the scope, affected components, and data at risk.
- Classify: Label as critical (funds at risk), high (user data exposed), medium (minor exposure), low (best practice gap).
- Document: Create an incident ticket with timeline and actions.
- If a smart contract vulnerability is suspected, invoke
pauseto halt trading immediately. - If the backend is compromised, revoke API keys and rotate secrets.
- If a frontend XSS is found, take the site down or serve a safe version.
- Block malicious IPs at the nginx / firewall level.
- Deploy a fix: upgrade smart contract, patch backend code, fix frontend.
- If the smart contract cannot be upgraded, consider deploying a new contract and migrating.
- Remove any backdoors or unauthorized access.
- Rotate all credentials (API keys, admin keys, database credentials).
- Verify the fix with the same tests that detected the issue.
- Monitor closely for recurrence.
- Gradually restore services (unpause contract, restore frontend).
- Notify affected users if their data was exposed.
- Conduct a root cause analysis within 7 days.
- Update the security audit checklist with lessons learned.
- Share findings with the development team.
- Update documentation and tests to prevent recurrence.
- Sentry: Tracks errors, performance, and traces. Configured via
SENTRY_DSN. - Prometheus: Collects metrics (request rates, error rates, response times, system resources).
- Grafana: Visualizes Prometheus metrics on customizable dashboards.
- ELK Stack (Elasticsearch, Logstash, Kibana): Centralized log aggregation and analysis.
- Filebeat: Ships nginx and application logs to Logstash.
- Monitor for:
- Repeated 401/403 responses (brute force attempts)
- Unusual spikes in 5xx errors
- Unexpected URL patterns (scanning / crawling)
- Large request payloads
Configure Prometheus alerting for:
- High Error Rate: >5% 5xx responses over 5 minutes
- High Latency: p99 response time >2s over 5 minutes
- Service Down: Target unreachable for >1 minute
- Rate Limit Hits: >100 rate limit responses per minute
- Certificate Expiry: SSL certificate expires in <30 days
- Nginx rate limiting zones tracked via metrics (if exported).
- Connection limiting prevents DDoS at the nginx layer.
- Basic WAF rules block common attack patterns (SQL injection, malicious user agents).
Review this guide regularly and update it as the project evolves. Security is an ongoing process, not a one-time checklist.