Security Model
Last Updated: May 19, 2025
This document describes the security architecture of the Typus Development Framework, outlining the components, patterns, and practices that ensure the security of applications built with the framework.
Security Architecture Overview
The Typus Development Framework implements a multi-layered security architecture that protects applications at various levels:
Authentication System
The authentication system verifies the identity of users and services accessing the application.
Authentication Components
Authentication Flow
JWT Token Structure
The framework uses JWT (JSON Web Tokens) for authentication with the following structure:
Access Token Payload:
{
"sub": "user_id",
"name": "username",
"email": "[email protected]",
"roles": ["user", "admin"],
"permissions": ["read:users", "write:users"],
"iat": 1619712000,
"exp": 1619715600,
"iss": "typus-auth"
}
Refresh Token Payload:
{
"sub": "user_id",
"jti": "unique_token_id",
"iat": 1619712000,
"exp": 1620316800,
"iss": "typus-auth"
}
Multi-factor Authentication
The framework supports multiple MFA methods:
- Time-based One-Time Password (TOTP): Compatible with authenticator apps
- Email Verification: One-time codes sent via email
- SMS Verification: One-time codes sent via SMS (optional)
Authorization System
The authorization system controls access to resources and operations based on user roles and permissions.
Role-Based Access Control (RBAC)
Authorization Flow
Permission Enforcement
The framework enforces permissions at multiple levels:
- Route Level: Using middleware to protect API endpoints
- Controller Level: Using decorators to protect controller methods
- Service Level: Using programmatic checks in service methods
- UI Level: Conditionally rendering UI elements based on permissions
Data Protection
The framework implements multiple layers of data protection to secure sensitive information.
Data Encryption
Sensitive Data Handling
The framework provides utilities for handling sensitive data:
- Password Hashing: Using bcrypt with appropriate work factors
- PII Encryption: Encrypting personally identifiable information
- Secure Configuration: Protecting secrets and credentials
- Data Masking: Masking sensitive data in logs and responses
API Security
The framework implements multiple measures to secure API endpoints.
API Security Components
API Security Measures
- Rate Limiting: Prevents abuse by limiting request frequency
- CORS Configuration: Controls cross-origin resource sharing
- Content Security Policy: Prevents XSS and data injection attacks
- Input Validation: Validates and sanitizes all input data
- CSRF Protection: Prevents cross-site request forgery attacks
Security Monitoring and Auditing
The framework includes comprehensive monitoring and auditing capabilities.
Security Monitoring Components
Audit Logging
The framework logs security-relevant events with the following information:
- Who: User identifier
- What: Action performed
- When: Timestamp
- Where: Source (IP, device)
- How: Method used
- Status: Success or failure
- Target: Resource affected
Secure Development Practices
The framework promotes secure development practices through its architecture and tooling.
Security by Design
Security Testing
The framework includes tools and patterns for security testing:
- Static Analysis: Identifying security issues in code
- Dependency Scanning: Checking for vulnerable dependencies
- Security Unit Tests: Testing security controls
- Penetration Testing: Identifying vulnerabilities in running applications
Vulnerability Protection
The framework includes protections against common vulnerabilities.
OWASP Top 10 Protections
Vulnerability | Protection Mechanism |
---|---|
Injection | Parameterized queries, input validation, ORM |
Broken Authentication | Secure authentication system, MFA, account lockout |
Sensitive Data Exposure | Encryption, data classification, secure transmission |
XML External Entities | Safe XML parsing, input validation |
Broken Access Control | RBAC, principle of least privilege, authorization checks |
Security Misconfiguration | Secure defaults, configuration validation |
Cross-Site Scripting | Output encoding, Content Security Policy |
Insecure Deserialization | Safe deserialization practices, input validation |
Using Components with Known Vulnerabilities | Dependency scanning, automatic updates |
Insufficient Logging & Monitoring | Comprehensive audit logging, security monitoring |
Security Configuration
The framework provides flexible security configuration options while maintaining secure defaults.
Configuration Areas
- Authentication: Configure authentication providers, token lifetimes, MFA settings
- Authorization: Define roles, permissions, and access control rules
- Encryption: Configure encryption algorithms, key management
- API Security: Configure rate limiting, CORS, CSP
- Logging: Configure audit logging, log storage, retention
Example Security Configuration
// Security configuration example
export const securityConfig = {
authentication: {
jwtSecret: process.env.JWT_SECRET,
accessTokenExpiry: '15m',
refreshTokenExpiry: '7d',
mfa: {
enabled: true,
methods: ['totp', 'email']
},
oauth: {
google: {
enabled: true,
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET
},
github: {
enabled: true,
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET
}
}
},
authorization: {
defaultRole: 'user',
superAdminRole: 'superadmin',
rbacEnabled: true
},
encryption: {
algorithm: 'aes-256-gcm',
keyRotationDays: 90
},
api: {
rateLimit: {
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // limit each IP to 100 requests per windowMs
},
cors: {
origin: process.env.ALLOWED_ORIGINS.split(','),
methods: ['GET', 'POST', 'PUT', 'DELETE'],
allowedHeaders: ['Content-Type', 'Authorization']
}
},
logging: {
audit: {
enabled: true,
sensitiveFields: ['password', 'creditCard', 'ssn']
}
}
};
Security Best Practices
The framework documentation includes security best practices for developers:
- Authentication: Implement MFA, secure password policies, proper token handling
- Authorization: Follow principle of least privilege, implement proper access controls
- Data Protection: Encrypt sensitive data, implement proper data handling
- API Security: Validate all inputs, implement rate limiting, use proper error handling
- Secure Coding: Follow secure coding guidelines, avoid common vulnerabilities
- Deployment: Use secure deployment practices, implement proper security controls
- Monitoring: Implement comprehensive logging and monitoring
Conclusion
The security architecture of the Typus Development Framework provides a comprehensive approach to application security. By implementing multiple layers of security controls, the framework helps developers build secure applications by default while providing flexibility for specific security requirements.
The security model follows industry best practices and addresses common security concerns, including authentication, authorization, data protection, and vulnerability prevention. The framework's security components work together to provide a robust security posture for applications built with the framework.