securenow 7.6.7 → 7.6.9

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.
Files changed (67) hide show
  1. package/NPM_README.md +13 -13
  2. package/README.md +21 -37
  3. package/app-config.js +5 -3
  4. package/cli/config.js +4 -3
  5. package/cli/diagnostics.js +54 -15
  6. package/cli/run.js +40 -11
  7. package/firewall-only.js +1 -1
  8. package/mcp/catalog.js +1 -1
  9. package/nextjs-webpack-config.js +3 -15
  10. package/nextjs.js +21 -23
  11. package/nuxt-server-plugin.mjs +20 -10
  12. package/package.json +23 -33
  13. package/register.js +1 -1
  14. package/tracing.js +17 -7
  15. package/web-vite.mjs +23 -13
  16. package/CONSUMING-APPS-GUIDE.md +0 -463
  17. package/docs/ALL-FRAMEWORKS-QUICKSTART.md +0 -1388
  18. package/docs/API-KEYS-GUIDE.md +0 -278
  19. package/docs/ARCHITECTURE.md +0 -408
  20. package/docs/AUTO-BODY-CAPTURE.md +0 -412
  21. package/docs/AUTO-SETUP-SUMMARY.md +0 -331
  22. package/docs/AUTO-SETUP.md +0 -419
  23. package/docs/AUTOMATIC-IP-CAPTURE.md +0 -359
  24. package/docs/BODY-CAPTURE-FIX.md +0 -261
  25. package/docs/BODY-CAPTURE-QUICKSTART.md +0 -147
  26. package/docs/CHANGELOG-NEXTJS.md +0 -235
  27. package/docs/COMPLETION-REPORT.md +0 -408
  28. package/docs/CUSTOMER-GUIDE.md +0 -364
  29. package/docs/EASIEST-SETUP.md +0 -342
  30. package/docs/ENVIRONMENT-VARIABLES.md +0 -166
  31. package/docs/ENVIRONMENTS.md +0 -60
  32. package/docs/EXPRESS-BODY-CAPTURE.md +0 -1028
  33. package/docs/EXPRESS-SETUP-GUIDE.md +0 -722
  34. package/docs/FINAL-SOLUTION.md +0 -335
  35. package/docs/FIREWALL-GUIDE.md +0 -440
  36. package/docs/IMPLEMENTATION-SUMMARY.md +0 -410
  37. package/docs/INDEX.md +0 -222
  38. package/docs/LOGGING-GUIDE.md +0 -704
  39. package/docs/LOGGING-QUICKSTART.md +0 -221
  40. package/docs/MCP-GUIDE.md +0 -58
  41. package/docs/NEXTJS-BODY-CAPTURE-COMPARISON.md +0 -323
  42. package/docs/NEXTJS-BODY-CAPTURE.md +0 -368
  43. package/docs/NEXTJS-GUIDE.md +0 -392
  44. package/docs/NEXTJS-QUICKSTART.md +0 -83
  45. package/docs/NEXTJS-SETUP-COMPLETE.md +0 -795
  46. package/docs/NEXTJS-WEBPACK-WARNINGS.md +0 -267
  47. package/docs/NEXTJS-WRAPPER-APPROACH.md +0 -414
  48. package/docs/NUXT-GUIDE.md +0 -173
  49. package/docs/QUICKSTART-BODY-CAPTURE.md +0 -293
  50. package/docs/REDACTION-EXAMPLES.md +0 -484
  51. package/docs/REQUEST-BODY-CAPTURE.md +0 -587
  52. package/docs/SOLUTION-SUMMARY.md +0 -312
  53. package/docs/VERCEL-OTEL-MIGRATION.md +0 -255
  54. package/examples/README.md +0 -265
  55. package/examples/express-with-logging.js +0 -137
  56. package/examples/instrumentation-with-auto-capture.ts +0 -41
  57. package/examples/next.config.js +0 -37
  58. package/examples/nextjs-api-route-with-body-capture.ts +0 -54
  59. package/examples/nextjs-env-example.txt +0 -32
  60. package/examples/nextjs-instrumentation.js +0 -36
  61. package/examples/nextjs-instrumentation.ts +0 -36
  62. package/examples/nextjs-middleware.js +0 -37
  63. package/examples/nextjs-middleware.ts +0 -37
  64. package/examples/nextjs-with-logging-example.md +0 -301
  65. package/examples/nextjs-with-options.ts +0 -36
  66. package/examples/test-nextjs-setup.js +0 -70
  67. package/postinstall.js +0 -296
@@ -1,587 +0,0 @@
1
- # 📝 Request Body Capture - Complete Guide
2
-
3
- SecureNow can automatically capture and trace request bodies (JSON, GraphQL, Form data) with built-in security controls!
4
-
5
- ---
6
-
7
- ## 🚀 Quick Start
8
-
9
- ### Enable Body Capture
10
-
11
- Add to your `.env.local` or environment variables:
12
-
13
- ```bash
14
- # Enable request body capture
15
- SECURENOW_CAPTURE_BODY=1
16
-
17
- # Optional: Set max body size (default: 10KB)
18
- SECURENOW_MAX_BODY_SIZE=20480
19
-
20
- # Optional: Add custom sensitive fields to redact
21
- SECURENOW_SENSITIVE_FIELDS=credit_card,email,phone
22
- ```
23
-
24
- **That's it!** Request bodies are now captured automatically with sensitive data redacted.
25
-
26
- ---
27
-
28
- ## 📊 What Gets Captured
29
-
30
- ### ✅ Supported Content Types (ALL with Redaction!)
31
-
32
- 1. **JSON** (`application/json`) - ✅ Fully Redacted
33
- ```json
34
- {
35
- "username": "john",
36
- "password": "[REDACTED]",
37
- "email": "john@example.com"
38
- }
39
- ```
40
- Sensitive object properties are automatically redacted.
41
-
42
- 2. **GraphQL** (`application/graphql`) - ✅ Fully Redacted
43
- ```graphql
44
- mutation Login {
45
- login(username: "john", password: "[REDACTED]") {
46
- token
47
- }
48
- }
49
- ```
50
- Sensitive fields in queries, mutations, and variables are redacted using regex pattern matching.
51
-
52
- 3. **Form Data** (`application/x-www-form-urlencoded`) - ✅ Fully Redacted
53
- ```
54
- username=john&password=[REDACTED]&remember=true
55
- ```
56
- Parsed into object and sensitive fields redacted.
57
-
58
- 4. **Multipart** (`multipart/form-data`) - ✅ Streaming Metadata Capture (v5.8.0+)
59
-
60
- Requires `SECURENOW_CAPTURE_MULTIPART=1`. Uses a streaming parser — file binary content is never buffered.
61
-
62
- ```json
63
- {
64
- "fields": { "description": "Profile update", "token": "[REDACTED]" },
65
- "files": [
66
- { "field": "avatar", "filename": "photo.jpg", "contentType": "image/jpeg", "size": 524288 }
67
- ]
68
- }
69
- ```
70
- Text field values are captured with sensitive-field redaction. File parts record metadata only (field, filename, content-type, size). Memory stays at ~few KB regardless of upload size.
71
-
72
- ### ❌ What's NOT Captured
73
-
74
- - GET requests (no body)
75
- - File binary content (only metadata when multipart capture is enabled)
76
- - Bodies larger than max size
77
- - Binary data
78
- - Non-POST/PUT/PATCH requests
79
-
80
- ---
81
-
82
- ## 🔒 Security Features
83
-
84
- ### Automatic Sensitive Field Redaction
85
-
86
- These fields are **automatically redacted**:
87
-
88
- ```javascript
89
- // Built-in sensitive fields
90
- [
91
- 'password', 'passwd', 'pwd',
92
- 'secret', 'token', 'api_key', 'apikey',
93
- 'access_token', 'auth', 'credentials',
94
- 'mysql_pwd', 'stripeToken',
95
- 'card', 'cardnumber', 'ccv', 'cvc', 'cvv',
96
- 'ssn', 'pin'
97
- ]
98
- ```
99
-
100
- **Example:**
101
- ```json
102
- // Original request
103
- {
104
- "username": "john",
105
- "password": "super_secret_123",
106
- "api_key": "sk_live_..."
107
- }
108
-
109
- // Captured in trace
110
- {
111
- "username": "john",
112
- "password": "[REDACTED]",
113
- "api_key": "[REDACTED]"
114
- }
115
- ```
116
-
117
- ### Add Custom Sensitive Fields
118
-
119
- ```bash
120
- # Add your own sensitive fields
121
- SECURENOW_SENSITIVE_FIELDS=credit_card,email,phone,address,dob
122
- ```
123
-
124
- Now these fields will also be redacted:
125
- ```json
126
- {
127
- "username": "john",
128
- "email": "[REDACTED]",
129
- "phone": "[REDACTED]",
130
- "address": "[REDACTED]"
131
- }
132
- ```
133
-
134
- ### Size Limits
135
-
136
- ```bash
137
- # Default: 10KB (10240 bytes)
138
- SECURENOW_MAX_BODY_SIZE=10240
139
-
140
- # Increase for larger payloads
141
- SECURENOW_MAX_BODY_SIZE=50000
142
-
143
- # Bodies larger than this show: [TOO LARGE: X bytes]
144
- ```
145
-
146
- ---
147
-
148
- ## 💡 Usage Examples
149
-
150
- ### Next.js API Route
151
-
152
- ```typescript
153
- // app/api/users/route.ts
154
- export async function POST(request: Request) {
155
- const body = await request.json();
156
-
157
- // Body is automatically captured in traces!
158
- // password fields are redacted
159
-
160
- return Response.json({ success: true });
161
- }
162
- ```
163
-
164
- **Trace will show:**
165
- ```json
166
- {
167
- "http.request.body": "{\"username\":\"john\",\"password\":\"[REDACTED]\"}",
168
- "http.request.body.size": 156,
169
- "http.request.body.type": "json"
170
- }
171
- ```
172
-
173
- ### Express.js
174
-
175
- ```javascript
176
- // server.js
177
- const express = require('express');
178
- const app = express();
179
-
180
- app.use(express.json());
181
-
182
- app.post('/api/login', (req, res) => {
183
- // req.body is automatically captured!
184
- // Sensitive fields are redacted
185
-
186
- res.json({ success: true });
187
- });
188
- ```
189
-
190
- ### GraphQL
191
-
192
- ```typescript
193
- // GraphQL queries are captured WITH REDACTION
194
- POST /graphql
195
- Content-Type: application/graphql
196
-
197
- mutation Login {
198
- login(username: "john", password: "secret123", token: "abc") {
199
- user { name }
200
- }
201
- }
202
- ```
203
-
204
- **Trace shows (with sensitive fields redacted):**
205
- ```json
206
- {
207
- "http.request.body": "mutation Login { login(username: \"john\", password: \"[REDACTED]\", token: \"[REDACTED]\") { user { name } } }",
208
- "http.request.body.type": "graphql",
209
- "http.request.body.size": 245
210
- }
211
- ```
212
-
213
- **GraphQL redaction works on:**
214
- - Arguments: `password: "value"` → `password: "[REDACTED]"`
215
- - Variables: `$token: "value"` → `$token: "[REDACTED]"`
216
- - Inline values in queries and mutations
217
-
218
- ---
219
-
220
- ## 🎯 Configuration Options
221
-
222
- ### Environment Variables
223
-
224
- | Variable | Default | Description |
225
- |----------|---------|-------------|
226
- | `SECURENOW_CAPTURE_BODY` | `0` (disabled) | Enable body capture |
227
- | `SECURENOW_MAX_BODY_SIZE` | `10240` (10KB) | Maximum body size to capture |
228
- | `SECURENOW_SENSITIVE_FIELDS` | `` | Comma-separated custom sensitive fields |
229
- | `SECURENOW_CAPTURE_MULTIPART` | `0` (disabled) | Enable multipart/form-data streaming capture (v5.8.0+) |
230
-
231
- ### Programmatic (Next.js)
232
-
233
- ```typescript
234
- // instrumentation.ts
235
- import { registerSecureNow } from 'securenow/nextjs';
236
-
237
- export function register() {
238
- registerSecureNow({
239
- serviceName: 'my-app',
240
- captureBody: true, // Enable body capture
241
- });
242
- }
243
- ```
244
-
245
- ---
246
-
247
- ## 🔍 Viewing in SecureNow
248
-
249
- ### Query Examples
250
-
251
- **Find all requests with specific body content:**
252
- ```
253
- http.request.body CONTAINS "username"
254
- ```
255
-
256
- **Find failed login attempts:**
257
- ```
258
- http.target = "/api/login"
259
- AND http.status_code = 401
260
- ```
261
-
262
- **Group by API endpoint and body size:**
263
- ```sql
264
- SELECT
265
- http.target,
266
- AVG(http.request.body.size) as avg_body_size,
267
- COUNT(*) as requests
268
- FROM spans
269
- WHERE http.request.body.size IS NOT NULL
270
- GROUP BY http.target
271
- ORDER BY avg_body_size DESC
272
- ```
273
-
274
- **Find large payloads:**
275
- ```
276
- http.request.body.size > 5000
277
- ```
278
-
279
- ---
280
-
281
- ## ⚠️ Privacy & Compliance
282
-
283
- ### GDPR Considerations
284
-
285
- Request bodies may contain personal data. Consider:
286
-
287
- 1. **Legal Basis** - Ensure you have legitimate interest or consent
288
- 2. **Data Minimization** - Only capture what you need
289
- 3. **Retention** - Configure SecureNow retention policies
290
- 4. **Anonymization** - Add more fields to redact list
291
-
292
- ### PCI-DSS Compliance
293
-
294
- **Never capture card data!** Built-in protection:
295
- - `card`, `cardnumber`, `cvv`, `cvc` → Automatically redacted
296
- - `stripeToken` → Automatically redacted
297
-
298
- Add more if needed:
299
- ```bash
300
- SECURENOW_SENSITIVE_FIELDS=cardName,cardExpiry,cardCvv
301
- ```
302
-
303
- ### HIPAA Compliance
304
-
305
- Add health-related fields:
306
- ```bash
307
- SECURENOW_SENSITIVE_FIELDS=ssn,medical_record,diagnosis,prescription
308
- ```
309
-
310
- ---
311
-
312
- ## 🎓 Best Practices
313
-
314
- ### ✅ DO
315
-
316
- 1. **Enable in development first** - Test thoroughly
317
- 2. **Add custom sensitive fields** - For your specific use case
318
- 3. **Set appropriate size limits** - Balance detail vs storage
319
- 4. **Monitor storage usage** - Bodies increase trace size
320
- 5. **Document what you capture** - In privacy policy
321
-
322
- ### ❌ DON'T
323
-
324
- 1. **Don't capture in production without review** - Check privacy implications
325
- 2. **Don't increase size limits too much** - Can impact performance
326
- 3. **Don't rely on it for audit logs** - Use dedicated audit logging
327
- 4. **Don't capture file uploads** - Too large and unnecessary
328
- 5. **Don't forget about retention** - Old data should be deleted
329
-
330
- ---
331
-
332
- ## 🐛 Debugging
333
-
334
- ### Body Not Captured?
335
-
336
- **Check:**
337
-
338
- 1. **Is capture enabled?**
339
- ```bash
340
- SECURENOW_CAPTURE_BODY=1
341
- ```
342
-
343
- 2. **Is it a supported method?**
344
- - Only POST, PUT, PATCH
345
- - Not GET, DELETE, HEAD
346
-
347
- 3. **Is it a supported content type?**
348
- - JSON: ✅
349
- - GraphQL: ✅
350
- - Form: ✅
351
- - Multipart: ❌ (by design)
352
-
353
- 4. **Is body size within limit?**
354
- ```bash
355
- # Increase if needed
356
- SECURENOW_MAX_BODY_SIZE=50000
357
- ```
358
-
359
- 5. **Check console on startup:**
360
- ```
361
- [securenow] 📝 Request body capture: ENABLED
362
- ```
363
-
364
- ### Partial Body Captured?
365
-
366
- Bodies are truncated if they exceed `maxBodySize`. Increase the limit:
367
-
368
- ```bash
369
- SECURENOW_MAX_BODY_SIZE=50000
370
- ```
371
-
372
- ### Sensitive Data Not Redacted?
373
-
374
- Add the field name:
375
-
376
- ```bash
377
- SECURENOW_SENSITIVE_FIELDS=mySecretField,anotherSecret
378
- ```
379
-
380
- Field matching is case-insensitive and uses `includes()`:
381
- - `password` matches `password`, `Password`, `user_password`
382
- - `token` matches `token`, `access_token`, `oauth_token`
383
-
384
- ---
385
-
386
- ## 📈 Performance Impact
387
-
388
- ### Overhead
389
-
390
- - **Memory:** ~10-50KB per request (for body storage)
391
- - **CPU:** < 1ms for redaction
392
- - **Storage:** Increases trace size by body size
393
-
394
- ### Optimization Tips
395
-
396
- 1. **Set reasonable size limits**
397
- ```bash
398
- SECURENOW_MAX_BODY_SIZE=10240 # 10KB
399
- ```
400
-
401
- 2. **Only enable where needed**
402
- ```typescript
403
- // Enable only for specific environments
404
- if (process.env.NODE_ENV === 'development') {
405
- process.env.SECURENOW_CAPTURE_BODY = '1';
406
- }
407
- ```
408
-
409
- 3. **Filter in SecureNow**
410
- - Use sampling to reduce volume
411
- - Set up trace tail sampling
412
-
413
- ---
414
-
415
- ## 🎯 Use Cases
416
-
417
- ### 1. Debug API Issues
418
-
419
- **Problem:** Users report API errors but you can't reproduce
420
-
421
- **Solution:** Capture body to see exact input
422
- ```
423
- http.target = "/api/checkout"
424
- AND http.status_code >= 400
425
- ```
426
-
427
- View `http.request.body` to see what caused the error.
428
-
429
- ### 2. Monitor GraphQL Queries
430
-
431
- **Problem:** Need to optimize slow GraphQL queries
432
-
433
- **Solution:** Capture GraphQL bodies
434
- ```
435
- http.request.body CONTAINS "query"
436
- AND duration > 1000ms
437
- ```
438
-
439
- See which queries are slow.
440
-
441
- ### 3. Track Feature Usage
442
-
443
- **Problem:** Want to know which API features are used
444
-
445
- **Solution:** Analyze request bodies
446
- ```sql
447
- SELECT
448
- COUNT(*) as usage,
449
- http.request.body
450
- FROM spans
451
- WHERE http.target = "/api/features"
452
- GROUP BY http.request.body
453
- ```
454
-
455
- ### 4. Validate Input Patterns
456
-
457
- **Problem:** Need to understand common input patterns
458
-
459
- **Solution:** Review captured bodies
460
- ```
461
- http.target = "/api/search"
462
- AND http.method = "POST"
463
- ```
464
-
465
- ---
466
-
467
- ## 🔧 Advanced Configuration
468
-
469
- ### Custom Redaction Logic
470
-
471
- For more complex redaction, you can use OpenTelemetry SpanProcessor:
472
-
473
- ```typescript
474
- // instrumentation.ts
475
- import { trace } from '@opentelemetry/api';
476
- import { registerSecureNow } from 'securenow/nextjs';
477
-
478
- class CustomRedactionProcessor {
479
- onStart(span) {
480
- // Custom logic here
481
- }
482
-
483
- onEnd(span) {
484
- const body = span.attributes['http.request.body'];
485
- if (body && typeof body === 'string') {
486
- // Apply custom redaction
487
- const redacted = body.replace(/\b\d{16}\b/g, '[CARD]'); // Redact card numbers
488
- span.setAttribute('http.request.body', redacted);
489
- }
490
- }
491
- }
492
-
493
- export function register() {
494
- registerSecureNow({ captureBody: true });
495
-
496
- // Add custom processor
497
- trace.getTracerProvider()
498
- .addSpanProcessor(new CustomRedactionProcessor());
499
- }
500
- ```
501
-
502
- ### Conditional Capture
503
-
504
- Enable only for specific routes:
505
-
506
- ```typescript
507
- // middleware.ts
508
- import { NextRequest, NextResponse } from 'next/server';
509
-
510
- export function middleware(request: NextRequest) {
511
- // Enable body capture only for API routes
512
- if (request.nextUrl.pathname.startsWith('/api/')) {
513
- process.env.SECURENOW_CAPTURE_BODY = '1';
514
- }
515
-
516
- return NextResponse.next();
517
- }
518
- ```
519
-
520
- ---
521
-
522
- ## ❓ FAQ
523
-
524
- ### Q: Will this capture passwords?
525
-
526
- **A:** No! Passwords are automatically redacted. Any field with `password`, `passwd`, or `pwd` in the name shows `[REDACTED]`.
527
-
528
- ### Q: What about credit cards?
529
-
530
- **A:** Automatically redacted. Fields with `card`, `cardnumber`, `cvv`, `cvc` are protected.
531
-
532
- ### Q: Can I disable redaction?
533
-
534
- **A:** Not recommended! But you can clear the sensitive fields list (⚠️ dangerous):
535
- ```bash
536
- SECURENOW_SENSITIVE_FIELDS="" # Don't do this!
537
- ```
538
-
539
- ### Q: Does this work with file uploads?
540
-
541
- **A:** Yes! Since v5.8.0, set `SECURENOW_CAPTURE_MULTIPART=1` to capture multipart/form-data requests. The streaming parser extracts text field values and file metadata (name, filename, content-type, size) without ever buffering file binary content. Memory stays bounded at ~few KB regardless of upload size.
542
-
543
- ### Q: What's the performance impact?
544
-
545
- **A:** Minimal. < 1ms CPU overhead, ~10-50KB memory per request.
546
-
547
- ### Q: Can I capture response bodies too?
548
-
549
- **A:** Not yet. Feature coming soon! Track issue #XXX.
550
-
551
- ### Q: Is this GDPR compliant?
552
-
553
- **A:** Depends on your use case. Review privacy implications and:
554
- - Add relevant fields to redaction list
555
- - Set appropriate retention
556
- - Document in privacy policy
557
-
558
- ---
559
-
560
- ## 🎉 Summary
561
-
562
- **Enable request body capture in 3 steps:**
563
-
564
- 1. ```bash
565
- SECURENOW_CAPTURE_BODY=1
566
- ```
567
-
568
- 2. ```bash
569
- # Optional: customize
570
- SECURENOW_MAX_BODY_SIZE=20480
571
- SECURENOW_SENSITIVE_FIELDS=email,phone
572
- ```
573
-
574
- 3. **Deploy!** Bodies are captured with sensitive data automatically redacted.
575
-
576
- **View in SecureNow:**
577
- - `http.request.body` - The captured body (redacted)
578
- - `http.request.body.size` - Body size in bytes
579
- - `http.request.body.type` - Content type (json, graphql, form)
580
-
581
- ---
582
-
583
- **Made with security in mind** 🔒
584
- # Current setup note
585
-
586
- Use `.securenow/credentials.json` for local and production. Body capture defaults live under `config.capture.*`; run `npx securenow init` to create secure defaults. Env-var examples in this older guide are legacy fallback snippets.
587
-