# Security Guide
**Comprehensive security features to protect your NornicDB deployment.**
## π Quick Start
NornicDB v1.0.0 includes **automatic security protection** on all HTTP endpoints. No configuration required for basic protection.
```bash
# Production mode (default) - strict security
NORNICDB_ENV=production
# Development mode - relaxed for local development
NORNICDB_ENV=development
```
## π Documentation
- **[HTTP Security Implementation](http-security.md)** - Complete implementation details
- **[Query Cache Security](query-cache-security.md)** - Query analysis and caching security model
- **[LLM & AST Security](llm-ast-security.md)** - Safe patterns for LLM integration and plugin security
- **[Cluster Security](../operations/cluster-security.md)** - Multi-node authentication
- **[Compliance Guide](../compliance/)** - GDPR, HIPAA, SOC2
## π Security Features
### HTTP Security Middleware β NEW in v1.0.0
All HTTP endpoints are automatically protected against:
| Attack Type | Protection | Status |
| ---------------------- | ---------------------------------------------- | --------- |
| **CSRF** | Token validation, injection prevention | β
Active |
| **SSRF** | Private IP blocking, metadata service blocking | β
Active |
| **XSS** | Script tag filtering, protocol validation | β
Active |
| **Header Injection** | CRLF/null byte filtering | β
Active |
| **Protocol Smuggling** | file://, gopher://, ftp:// blocked | β
Active |
### Query Analysis Security
The query cache system uses conservative keyword detection:
| Concern | Status | Notes |
| ------------------------------ | ------------- | ---------------------------------- |
| **Write ops hidden as reads** | β
Protected | Not possible in valid Cypher |
| **Cache poisoning** | β
Protected | Keys include query + parameters |
| **Read ops marked as writes** | β‘ Accepted | Performance impact only, not security |
See **[Query Cache Security](query-cache-security.md)** for full details.
### Authentication & Authorization
- **JWT Authentication** - Stateless token-based auth
- **RBAC** - Role-based access control
- **API Keys** - Service-to-service authentication
### Data Protection
- **Field-Level Encryption** - AES-256-GCM encryption
- **TLS/HTTPS** - Required in production mode
- **Audit Logging** - Complete operation history
## π‘οΈ Attack Prevention
### SSRF Protection
Automatically blocks requests to:
```
β Private IPs (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16)
β Localhost (127.0.0.0/8) - in production
β Link-local (169.254.0.0/16)
β AWS/Azure/GCP metadata services
β Dangerous protocols (file://, gopher://, ftp://)
```
### Token Validation
Automatically validates:
```
β
Bearer tokens in Authorization header
β
Query parameter tokens (SSE/WebSocket)
β
OAuth state parameters
β
Callback/redirect URLs
```
## π§ Configuration
### Environment Variables
```bash
# Production mode (strict) - DEFAULT
NORNICDB_ENV=production
# Development mode (allows localhost)
NORNICDB_ENV=development
# Allow HTTP (not recommended for production)
NORNICDB_ALLOW_HTTP=true
```
### Production vs Development
| Feature | Production | Development |
| ----------------------- | ---------- | ----------- |
| Block localhost | β
Yes | β No |
| Require HTTPS | β
Yes | β No |
| Block private IPs | β
Yes | β
Yes |
| Block metadata services | β
Yes | β
Yes |
## π Usage Examples
### Automatic Protection (Default)
```go
// No code changes needed - middleware is active!
// All endpoints automatically protected
server := nornicdb.NewServer()
server.Start() // Security middleware included
```
### Manual Validation (Optional)
```go
import "github.com/orneryd/nornicdb/pkg/security"
// Validate external URLs before making requests
if err := security.ValidateURL(webhookURL, false, false); err != nil {
return fmt.Errorf("invalid webhook: %w", err)
}
// Validate tokens before processing
if err := security.ValidateToken(apiKey); err != nil {
return fmt.Errorf("invalid token: %w", err)
}
```
## π Test Coverage
- **19 unit tests** covering 30+ attack scenarios
- **8 integration tests** with full HTTP stack
- **Performance:** < 10Β΅s overhead per request
## π See Also
- **[HTTP Security Implementation](http-security.md)** - Full technical details
- **[Compliance Guide](../compliance/)** - Regulatory compliance
- **[Operations Security](../operations/cluster-security.md)** - Cluster authentication
- **[OWASP SSRF Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html)**
- **[OWASP CSRF Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html)**
---
**Secure your deployment** β **[Implementation Details](http-security.md)**