This section covers all security-related aspects of LogseqSpringThing, including authentication, authorization, API security, and best practices for deployment.
Comprehensive guide to the Nostr-based authentication system, including:
- NIP-07 browser extension integration
- Session management
- API key handling (for regular users)
- Role-based access control (RBAC)
The Binary Protocol Documentation includes security considerations for:
- Input validation
- Memory safety
- Rate limiting
- Data integrity
The WebSocket API Documentation covers:
- Authentication requirements for WebSocket connections
- Message validation
- Connection security
- Rate limiting
# Authentication
AUTH_TOKEN_EXPIRY=3600 # Session token expiry in seconds
POWER_USER_PUBKEYS=pubkey1,pubkey2,pubkey3 # Comma-separated power users
# API Keys (for power users)
PERPLEXITY_API_KEY=your-key
OPENAI_API_KEY=your-key
RAGFLOW_API_KEY=your-keyAll authenticated API requests must include:
X-Nostr-Pubkey: <user-public-key>
Authorization: Bearer <session-token>
Configure allowed origins in protected_settings.json:
{
"security": {
"allowed_origins": [
"http://localhost:3000",
"https://your-domain.com"
]
}
}- Use environment variables for sensitive data
- Enable debug logging for auth services
- Test with multiple NIP-07 extensions
- Verify session expiry handling
- Use HTTPS for all connections
- Configure proper CORS origins
- Set appropriate session timeouts
- Enable audit logging
- Configure rate limiting
- Use strong API keys
- Regular security updates
- Monitor for suspicious activity
const response = await fetch('/api/protected-endpoint', {
headers: {
'X-Nostr-Pubkey': user.pubkey,
'Authorization': `Bearer ${sessionToken}`,
'Content-Type': 'application/json'
}
});const ws = new WebSocket(`wss://your-domain/wss?token=${sessionToken}`);const hasAccess = await nostrAuth.checkFeatureAccess('premium-feature');
if (!hasAccess) {
throw new Error('Feature requires premium access');
}- Always verify Nostr event signatures server-side
- Use secure session token generation (UUID v4)
- Implement proper session expiry
- Clear sessions on logout
- Check feature access for protected operations
- Validate user roles before API key operations
- Use environment variables for power user configuration
- Implement least privilege principle
- Sanitize all user inputs
- Use parameterized queries for database operations
- Implement rate limiting on sensitive endpoints
- Log security events for auditing
- Use TLS/SSL for all connections
- Implement proper CORS policies
- Validate WebSocket message formats
- Set appropriate timeout values
- Store tokens securely (localStorage/sessionStorage)
- Clear sensitive data on logout
- Validate server responses
- Implement client-side rate limiting
-
Session Hijacking
- Mitigated by: HTTPS, secure token generation, session expiry
-
Unauthorized Access
- Mitigated by: Nostr signature verification, role-based access control
-
API Key Exposure
- Mitigated by: Environment variables, power user restrictions
-
DoS Attacks
- Mitigated by: Rate limiting, connection limits, message size limits
-
Data Tampering
- Mitigated by: Binary protocol validation, bounds checking
Report security vulnerabilities to: security@logseqspringthing.com
- Detection: Monitor logs for suspicious activity
- Containment: Revoke compromised sessions/tokens
- Investigation: Analyze audit logs
- Remediation: Apply security patches
- Communication: Notify affected users