yinzerflow 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,282 +0,0 @@
1
- # Security Overview
2
-
3
- YinzerFlow implements a comprehensive security-first approach with built-in protections against common web vulnerabilities. This overview covers the key security features and how they work together to protect your applications.
4
-
5
- ## Security Architecture
6
-
7
- YinzerFlow's security is built on multiple layers of protection:
8
-
9
- ```
10
- ┌─────────────────────────────────────────────────────────────┐
11
- │ Application Layer │
12
- │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
13
- │ │ Route Security│ │ Error Handling │ │ Logging │ │
14
- │ │ - Validation │ │ - Catching │ │ - Audit │ │
15
- │ │ - Sanitization│ │ - Reporting │ │ - Monitor │ │
16
- │ └─────────────────┘ └─────────────────┘ └─────────────┘ │
17
- └─────────────────────────────────────────────────────────────┘
18
- ┌─────────────────────────────────────────────────────────────┐
19
- │ Framework Layer │
20
- │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
21
- │ │ Body Parsing │ │ CORS │ │ IP Security │ │
22
- │ │ - DoS Protection│ │ - Origin Valid │ │ - Spoofing │ │
23
- │ │ - Size Limits │ │ - Headers │ │ - Detection │ │
24
- │ └─────────────────┘ └─────────────────┘ └─────────────┘ │
25
- └─────────────────────────────────────────────────────────────┘
26
- ┌─────────────────────────────────────────────────────────────┐
27
- │ Network Layer │
28
- │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────┐ │
29
- │ │ HTTP Headers │ │ Request Size │ │ Timeouts │ │
30
- │ │ - Validation │ │ - Limits │ │ - Limits │ │
31
- │ │ - Sanitization│ │ - Protection │ │ - Graceful │ │
32
- │ └─────────────────┘ └─────────────────┘ └─────────────┘ │
33
- └─────────────────────────────────────────────────────────────┘
34
- ```
35
-
36
- ## Core Security Features
37
-
38
- ### 🛡️ Body Parsing Security
39
- **Protection**: DoS attacks, prototype pollution, memory exhaustion
40
- **Implementation**: Configurable size limits, depth validation, type checking
41
- **Documentation**: [Body Parsing Security](./body-parsing.md)
42
-
43
- ```typescript
44
- const secureApp = new YinzerFlow({
45
- bodyParser: {
46
- json: {
47
- maxSize: 262144, // 256KB limit
48
- maxDepth: 10, // Prevent stack overflow
49
- allowPrototypeProperties: false, // Block prototype pollution
50
- maxKeys: 1000 // Prevent memory exhaustion
51
- },
52
- fileUploads: {
53
- maxFileSize: 10485760, // 10MB per file
54
- blockedExtensions: ['.exe', '.bat', '.cmd'], // Block dangerous files
55
- maxFiles: 10
56
- }
57
- }
58
- });
59
- ```
60
-
61
- ### 🛡️ CORS Security
62
- **Protection**: Cross-origin attacks, unauthorized access
63
- **Implementation**: Origin validation, header sanitization, preflight handling
64
- **Documentation**: [CORS Security](./cors.md)
65
-
66
- ```typescript
67
- const secureApp = new YinzerFlow({
68
- cors: {
69
- enabled: true,
70
- origin: ['https://yourdomain.com'], // Specific origins only
71
- credentials: true,
72
- methods: ['GET', 'POST', 'PUT', 'DELETE'],
73
- allowedHeaders: ['Content-Type', 'Authorization']
74
- }
75
- });
76
- ```
77
-
78
- ### 🛡️ IP Security
79
- **Protection**: IP spoofing, load balancer bypass
80
- **Implementation**: Trusted proxy validation, chain length limits
81
- **Documentation**: [IP Security](./ip-security.md)
82
-
83
- ```typescript
84
- const secureApp = new YinzerFlow({
85
- ipSecurity: {
86
- trustedProxies: ['127.0.0.1', '192.168.1.10'],
87
- allowPrivateIps: true,
88
- headerPreference: ['x-forwarded-for', 'x-real-ip'],
89
- maxChainLength: 10,
90
- detectSpoofing: true
91
- }
92
- });
93
- ```
94
-
95
- ### 🛡️ Route Security
96
- **Protection**: Path traversal, parameter injection, method confusion
97
- **Implementation**: Parameter validation, path normalization, method validation
98
- **Documentation**: [Route Security](../core/routes.md#security-considerations)
99
-
100
- ```typescript
101
- // Automatic protection against:
102
- // - Path traversal: /api/../etc/passwd
103
- // - Parameter injection: /api/users/'; DROP TABLE users; --
104
- // - Method confusion: Invalid HTTP methods
105
- app.get('/api/users/:id', ({ request }) => {
106
- const userId = request.params.id; // Automatically validated
107
- return { userId };
108
- });
109
- ```
110
-
111
- ### 🛡️ Error Handling Security
112
- **Protection**: Information leakage, error-based attacks
113
- **Implementation**: Safe error responses, no stack traces in production
114
- **Documentation**: [Error Handling Security](../core/error-handling.md)
115
-
116
- ```typescript
117
- // Global error handler prevents information leakage
118
- app.onError(({ response }, error) => {
119
- response.setStatusCode(500);
120
- return { error: 'Internal server error' }; // No sensitive details
121
- });
122
- ```
123
-
124
- ### 🛡️ Logging Security
125
- **Protection**: Log injection, sensitive data exposure
126
- **Implementation**: Structured logging, sensitive data filtering
127
- **Documentation**: [Logging Security](../core/logging.md)
128
-
129
- ```typescript
130
- const secureApp = new YinzerFlow({
131
- logger: {
132
- level: 'info',
133
- sensitiveFields: ['password', 'token', 'secret'],
134
- maskPatterns: [/credit_card_\d+/, /ssn_\d+/]
135
- }
136
- });
137
- ```
138
-
139
- ## Security Configuration Patterns
140
-
141
- For detailed configuration examples and patterns, see [Configuration Patterns](../configuration/configuration-patterns.md).
142
-
143
- ### Security-First Configuration Principles
144
-
145
- 1. **Principle of Least Privilege**
146
- - Configure only the features you need
147
- - Use specific origins instead of wildcards
148
- - Limit file upload types and sizes
149
- - Restrict HTTP methods to those you use
150
-
151
- 2. **Defense in Depth**
152
- - Combine multiple security layers
153
- - Validate at both framework and application levels
154
- - Use hooks for additional validation
155
- - Implement custom security checks
156
-
157
- 3. **Secure by Default**
158
- - YinzerFlow's defaults are secure
159
- - Explicitly configure only when needed
160
- - Test security configurations thoroughly
161
- - Monitor for security events
162
-
163
- 4. **Regular Security Updates**
164
- - Keep YinzerFlow updated
165
- - Monitor security advisories
166
- - Review and update configurations
167
- - Test security features regularly
168
-
169
- ## Security Best Practices
170
-
171
- For detailed security configuration examples and best practices, see [Configuration Patterns](../configuration/configuration-patterns.md).
172
-
173
- ### Key Security Principles
174
-
175
- 1. **Principle of Least Privilege** - Configure only what you need
176
- 2. **Defense in Depth** - Multiple security layers
177
- 3. **Secure by Default** - YinzerFlow's defaults are secure
178
- 4. **Regular Security Updates** - Keep configurations current
179
-
180
- ## Security Monitoring
181
-
182
- ### Built-in Security Logging
183
- YinzerFlow automatically logs security events:
184
-
185
- ```typescript
186
- // Automatic logging of:
187
- // - CORS violations
188
- // - Body parsing errors
189
- // - IP spoofing attempts
190
- // - Route validation failures
191
- // - Security configuration errors
192
- ```
193
-
194
- ### Custom Security Monitoring
195
- Add custom security monitoring with hooks:
196
-
197
- ```typescript
198
- app.beforeAll([
199
- ({ request, response }) => {
200
- // Monitor for suspicious patterns
201
- const suspiciousPatterns = [
202
- /\.\.\//, // Path traversal
203
- /<script>/i, // XSS attempts
204
- /union\s+select/i, // SQL injection
205
- /javascript:/i // Protocol injection
206
- ];
207
-
208
- const url = request.url;
209
- const body = JSON.stringify(request.body);
210
-
211
- for (const pattern of suspiciousPatterns) {
212
- if (pattern.test(url) || pattern.test(body)) {
213
- console.warn('🚨 Suspicious request detected:', {
214
- ip: request.ipAddress,
215
- url: request.url,
216
- pattern: pattern.source
217
- });
218
- response.setStatusCode(400);
219
- return { error: 'Invalid request' };
220
- }
221
- }
222
- }
223
- ]);
224
- ```
225
-
226
- ## Security Testing
227
-
228
- ### Automated Security Testing
229
- Test your security configuration:
230
-
231
- ```typescript
232
- // Test body parsing limits
233
- const testBodyLimits = async () => {
234
- const response = await fetch('http://localhost:3000/api/test', {
235
- method: 'POST',
236
- headers: { 'Content-Type': 'application/json' },
237
- body: JSON.stringify({ data: 'x'.repeat(300000) }) // Exceeds 256KB limit
238
- });
239
-
240
- console.assert(response.status === 413, 'Body size limit not enforced');
241
- };
242
-
243
- // Test CORS configuration
244
- const testCORS = async () => {
245
- const response = await fetch('http://localhost:3000/api/test', {
246
- method: 'OPTIONS',
247
- headers: { 'Origin': 'https://malicious.com' }
248
- });
249
-
250
- console.assert(response.status === 403, 'CORS origin validation not working');
251
- };
252
- ```
253
-
254
- ## Security Checklist
255
-
256
- Before deploying to production, verify:
257
-
258
- - [ ] Body parsing limits configured appropriately
259
- - [ ] CORS origins restricted to trusted domains
260
- - [ ] IP security configured for your infrastructure
261
- - [ ] File upload restrictions in place
262
- - [ ] Error handling prevents information leakage
263
- - [ ] Logging configured to avoid sensitive data exposure
264
- - [ ] Security headers enabled
265
- - [ ] HTTPS configured (if applicable)
266
- - [ ] Security monitoring in place
267
- - [ ] Regular security updates scheduled
268
-
269
- ## Getting Help
270
-
271
- For detailed security documentation:
272
- - **[Body Parsing](./body-parsing.md)** - File upload and JSON parsing security
273
- - **[CORS](./cors.md)** - Cross-origin request security
274
- - **[IP Security](./ip-security.md)** - Client IP validation and protection
275
- - **[Logging](../core/logging.md)** - Secure logging practices
276
- - **[Error Handling](../core/error-handling.md)** - Secure error handling patterns
277
-
278
- For security issues or questions:
279
- - Check the security documentation above
280
- - Review the security configuration examples
281
- - Test your security setup thoroughly
282
- - Consider security implications of all custom code
@@ -1,184 +0,0 @@
1
- # Getting Started with YinzerFlow
2
-
3
- YinzerFlow is a lightweight, modular HTTP server framework for Node.js built with TypeScript. It provides a powerful routing system, comprehensive security features, and built-in Pittsburgh personality with flexible logging and configuration options.
4
-
5
- ## What is YinzerFlow?
6
-
7
- YinzerFlow is designed for developers who want:
8
- - **Security-first approach** with built-in protections against common web vulnerabilities
9
- - **TypeScript-first development** with full type safety and IntelliSense support
10
- - **Flexible configuration** for different deployment environments and use cases
11
- - **Pittsburgh personality** with witty logging and error messages
12
- - **Modular architecture** that scales from simple APIs to complex microservices
13
-
14
- ## Quick Start
15
-
16
- For a complete quick reference with all common patterns, see [Quick Reference](./quick-reference.md).
17
-
18
- ### Installation
19
-
20
- ```bash
21
- # Using npm
22
- npm install yinzerflow
23
-
24
- # Using Yarn
25
- yarn add yinzerflow
26
-
27
- # Using Bun
28
- bun add yinzerflow
29
- ```
30
-
31
- ### Minimal Example
32
-
33
- ```typescript
34
- import { YinzerFlow } from 'yinzerflow';
35
-
36
- // Create a new YinzerFlow instance
37
- const app = new YinzerFlow({ port: 3000 });
38
-
39
- // Add a simple route
40
- app.get('/hello', () => {
41
- return { message: 'Hello, World!' };
42
- });
43
-
44
- // Start the server
45
- await app.listen();
46
- // Although you can log the server is started, the built in logging will log this for you already when the server is listening
47
- ```
48
-
49
- ### Basic API Example
50
-
51
- ```typescript
52
- import { YinzerFlow } from 'yinzerflow';
53
-
54
- const app = new YinzerFlow({ port: 3000 });
55
-
56
- // GET route with parameters
57
- app.get('/api/users/:id', ({ request }) => {
58
- const userId = request.params.id;
59
- const includeProfile = request.query.include_profile;
60
-
61
- return {
62
- id: userId,
63
- name: 'John Doe',
64
- includeProfile: !!includeProfile
65
- };
66
- });
67
-
68
- // POST route with body parsing
69
- app.post('/api/users', ({ request }) => {
70
- const userData = request.body;
71
-
72
- return {
73
- message: 'User created successfully',
74
- data: userData
75
- };
76
- });
77
-
78
- await app.listen();
79
- ```
80
-
81
- ### Graceful Shutdown
82
-
83
- YinzerFlow automatically handles graceful shutdown for SIGTERM and SIGINT signals. No manual setup required:
84
-
85
- ```typescript
86
- import { YinzerFlow } from 'yinzerflow';
87
-
88
- const app = new YinzerFlow({ port: 3000 });
89
-
90
- // Add your routes
91
- app.get('/hello', () => {
92
- return { message: 'Hello, World!' };
93
- });
94
-
95
- // Start the server - graceful shutdown is automatically configured
96
- await app.listen();
97
- ```
98
-
99
- **That's it!** YinzerFlow will automatically:
100
- - Listen for SIGTERM and SIGINT signals
101
- - Log the shutdown process with Pittsburgh personality
102
- - Close the server gracefully
103
- - Exit the process cleanly
104
-
105
- For custom shutdown handling, see [Advanced Configuration](./advanced-configuration-options.md).
106
-
107
- ## Documentation Overview
108
-
109
- ### Core Features
110
-
111
- - **[Routes](./core/routes.md)** - Comprehensive routing system with HTTP methods, parameters, hooks, and groups
112
- - **[Context Object](./core/context.md)** - Central interface for request data, response controls, and request lifecycle
113
- - **[Request Object](./core/request.md)** - Access headers, body, query parameters, route parameters, and raw body
114
- - **[Response Object](./core/response.md)** - Set status codes, headers, and return various response types
115
- - **[Error Handling](./core/error-handling.md)** - Automatic error catching, custom error handlers, and comprehensive error management
116
-
117
- ### Security & Configuration
118
-
119
- - **[Security Overview](./security/security-overview.md)** - Comprehensive security features and configuration patterns
120
- - **[Body Parsing](./security/body-parsing.md)** - Secure parsing of JSON, file uploads, and form data with DoS protection
121
- - **[CORS](./security/cors.md)** - Cross-Origin Resource Sharing with comprehensive security measures
122
- - **[IP Security](./security/ip-security.md)** - Client IP validation and spoofing protection for load balancers and CDNs
123
- - **[Logging](./core/logging.md)** - Flexible logging with custom logger support and Pittsburgh personality
124
- - **[Configuration Patterns](./configuration/configuration-patterns.md)** - Common configuration patterns and best practices
125
- - **[Advanced Configuration](./configuration/advanced-configuration-options.md)** - Fine-tune security, performance, and functionality
126
-
127
- ### Common Use Cases
128
-
129
- - **API Development**: Create RESTful APIs with automatic body parsing and security
130
- - **File Uploads**: Handle multipart form data with size limits and type validation
131
- - **Authentication**: Implement middleware hooks for token validation and user sessions
132
- - **Rate Limiting**: Add before hooks to limit request frequency and prevent abuse
133
- - **Load Balancer Integration**: Configure trusted proxies for accurate client IP detection
134
- - **Production Monitoring**: Use custom loggers with structured logging and monitoring
135
-
136
- ## Key Features
137
-
138
- ### 🛡️ Security First
139
- - Built-in protection against DoS attacks, prototype pollution, and memory exhaustion
140
- - Automatic security headers and CORS validation
141
- - IP spoofing protection with trusted proxy validation
142
- - Comprehensive input validation and sanitization
143
-
144
- ### 🔧 Flexible Configuration
145
- - Configurable body parsing limits and security settings
146
- - Custom logger integration (Winston, Pino, etc.)
147
- - Environment-specific configurations (development, production, high-security)
148
- - Graceful shutdown with connection timeout handling
149
-
150
- ### 🚀 TypeScript Native
151
- - Full TypeScript support with comprehensive type definitions
152
- - IntelliSense support for all framework features
153
- - Type-safe request/response handling
154
- - Generic support for custom body and response types
155
-
156
- ### 🎭 Pittsburgh Personality
157
- - Witty logging messages and error handling
158
- - Built-in Pittsburgh-themed personality
159
- - Customizable logging with familiar `log.info()` interface
160
- - Network request logging with nginx-style formatting
161
-
162
- ## Next Steps
163
-
164
- 1. **Start with Routes**: Learn the routing system in [routes.md](./routes.md)
165
- 2. **Understand Requests**: Explore request handling in [request.md](./request.md)
166
- 3. **Configure Security**: Set up IP security and CORS in [ip-security.md](./ip-security.md) and [cors.md](./cors.md)
167
- 4. **Customize Logging**: Implement custom loggers in [logging.md](./core/logging.md)
168
- 5. **Advanced Configuration**: Fine-tune settings in [advanced-configuration-options.md](./advanced-configuration-options.md)
169
-
170
- ## Examples
171
-
172
- Check out the `/example` directory for complete working examples:
173
-
174
- - **TypeScript Example** - Full-featured API with authentication, file uploads, and custom logging
175
- - **Basic Example** - Minimal server setup for quick prototyping
176
- - **Production Example** - High-security configuration with monitoring and graceful shutdown
177
-
178
- ## Contributing
179
-
180
- We welcome contributions! Please see our contribution guidelines and feel free to submit pull requests for documentation improvements, bug fixes, or new features.
181
-
182
- ---
183
-
184
- **Ready to build something amazing?** Start with the [Routes documentation](./routes.md) to learn how to create your first API endpoints!