securenow 6.0.2 → 6.1.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.
Files changed (87) hide show
  1. package/CONSUMING-APPS-GUIDE.md +455 -0
  2. package/NPM_README.md +2029 -0
  3. package/README.md +297 -40
  4. package/SKILL-API.md +634 -0
  5. package/SKILL-CLI.md +454 -0
  6. package/cidr.js +83 -0
  7. package/cli/apps.js +585 -0
  8. package/cli/auth.js +280 -0
  9. package/cli/client.js +115 -0
  10. package/cli/config.js +173 -0
  11. package/cli/diagnostics.js +387 -0
  12. package/cli/firewall.js +100 -0
  13. package/cli/fp.js +638 -0
  14. package/cli/init.js +201 -0
  15. package/cli/monitor.js +440 -0
  16. package/cli/run.js +148 -0
  17. package/cli/security.js +980 -0
  18. package/cli/ui.js +386 -0
  19. package/cli/utils.js +127 -0
  20. package/cli.js +466 -455
  21. package/console-instrumentation.js +147 -136
  22. package/docs/ALL-FRAMEWORKS-QUICKSTART.md +1377 -455
  23. package/docs/API-KEYS-GUIDE.md +233 -0
  24. package/docs/ARCHITECTURE.md +3 -3
  25. package/docs/AUTO-BODY-CAPTURE.md +1 -1
  26. package/docs/AUTO-SETUP-SUMMARY.md +331 -0
  27. package/docs/AUTO-SETUP.md +4 -4
  28. package/docs/AUTOMATIC-IP-CAPTURE.md +5 -5
  29. package/docs/BODY-CAPTURE-FIX.md +261 -0
  30. package/docs/BODY-CAPTURE-QUICKSTART.md +2 -2
  31. package/docs/CHANGELOG-NEXTJS.md +1 -35
  32. package/docs/COMPLETION-REPORT.md +408 -0
  33. package/docs/CUSTOMER-GUIDE.md +16 -16
  34. package/docs/EASIEST-SETUP.md +5 -5
  35. package/docs/ENVIRONMENT-VARIABLES.md +880 -652
  36. package/docs/EXPRESS-BODY-CAPTURE.md +13 -12
  37. package/docs/EXPRESS-SETUP-GUIDE.md +719 -720
  38. package/docs/FINAL-SOLUTION.md +335 -0
  39. package/docs/FIREWALL-GUIDE.md +426 -0
  40. package/docs/IMPLEMENTATION-SUMMARY.md +410 -0
  41. package/docs/INDEX.md +22 -4
  42. package/docs/LOGGING-GUIDE.md +701 -708
  43. package/docs/LOGGING-QUICKSTART.md +234 -255
  44. package/docs/NEXTJS-BODY-CAPTURE-COMPARISON.md +323 -0
  45. package/docs/NEXTJS-BODY-CAPTURE.md +2 -2
  46. package/docs/NEXTJS-GUIDE.md +14 -14
  47. package/docs/NEXTJS-QUICKSTART.md +1 -1
  48. package/docs/NEXTJS-SETUP-COMPLETE.md +795 -0
  49. package/docs/NEXTJS-WRAPPER-APPROACH.md +1 -1
  50. package/docs/NUXT-GUIDE.md +166 -0
  51. package/docs/QUICKSTART-BODY-CAPTURE.md +2 -2
  52. package/docs/REDACTION-EXAMPLES.md +1 -1
  53. package/docs/REQUEST-BODY-CAPTURE.md +19 -10
  54. package/docs/SOLUTION-SUMMARY.md +312 -0
  55. package/docs/VERCEL-OTEL-MIGRATION.md +3 -3
  56. package/examples/README.md +6 -6
  57. package/examples/instrumentation-with-auto-capture.ts +1 -1
  58. package/examples/nextjs-env-example.txt +2 -2
  59. package/examples/nextjs-instrumentation.js +1 -1
  60. package/examples/nextjs-instrumentation.ts +1 -1
  61. package/examples/nextjs-with-logging-example.md +6 -6
  62. package/examples/nextjs-with-options.ts +1 -1
  63. package/examples/test-nextjs-setup.js +1 -1
  64. package/firewall-cloud.js +212 -0
  65. package/firewall-iptables.js +139 -0
  66. package/firewall-only.js +38 -0
  67. package/firewall-tcp.js +74 -0
  68. package/firewall.js +720 -0
  69. package/free-trial-banner.js +174 -0
  70. package/nextjs-auto-capture.js +199 -207
  71. package/nextjs-middleware.js +186 -181
  72. package/nextjs-webpack-config.js +88 -53
  73. package/nextjs-wrapper.js +158 -158
  74. package/nextjs.d.ts +1 -1
  75. package/nextjs.js +639 -647
  76. package/nuxt-server-plugin.mjs +423 -0
  77. package/nuxt.d.ts +60 -0
  78. package/nuxt.mjs +75 -0
  79. package/package.json +186 -164
  80. package/postinstall.js +6 -6
  81. package/register.d.ts +1 -1
  82. package/register.js +39 -4
  83. package/resolve-ip.js +77 -0
  84. package/tracing.d.ts +2 -1
  85. package/tracing.js +295 -34
  86. package/web-vite.mjs +239 -156
  87. package/LICENSE +0 -15
@@ -0,0 +1,323 @@
1
+ # Next.js Body Capture - Choosing the Right Approach
2
+
3
+ ## 🎯 Two Approaches Available
4
+
5
+ SecureNow offers two ways to capture request bodies in Next.js:
6
+
7
+ 1. **Wrapper Approach** (Recommended ✅)
8
+ 2. **Middleware Approach** (Use with caution ⚠️)
9
+
10
+ ---
11
+
12
+ ## ✅ Wrapper Approach (RECOMMENDED)
13
+
14
+ ### How It Works
15
+
16
+ Wrap individual API route handlers to capture bodies **inside the handler**:
17
+
18
+ ```typescript
19
+ import { withSecureNow } from 'securenow/nextjs-wrapper';
20
+
21
+ export const POST = withSecureNow(async (request: Request) => {
22
+ const body = await request.json();
23
+ return Response.json({ success: true });
24
+ });
25
+ ```
26
+
27
+ ### ✅ Pros
28
+
29
+ - **Zero middleware conflicts** - Doesn't interfere with NextAuth or other middleware
30
+ - **Never blocks requests** - Runs after routing is complete
31
+ - **Per-route control** - Wrap only the routes you need
32
+ - **Non-invasive** - Your middleware stays unchanged
33
+ - **Safe** - Runs inside your handler, can't prevent handler execution
34
+ - **Background capture** - Doesn't delay responses
35
+
36
+ ### ❌ Cons
37
+
38
+ - Requires wrapping each route individually (but only the ones you want!)
39
+ - Slightly more verbose (one extra line per route)
40
+
41
+ ### When to Use
42
+
43
+ - ✅ You have NextAuth or other middleware
44
+ - ✅ You want zero conflicts
45
+ - ✅ You want fine-grained control
46
+ - ✅ You prioritize reliability
47
+ - ✅ **This is the recommended approach for most users**
48
+
49
+ ### Setup
50
+
51
+ **Step 1:** Enable in .env.local
52
+ ```bash
53
+ SECURENOW_CAPTURE_BODY=1
54
+ ```
55
+
56
+ **Step 2:** Wrap your API routes
57
+ ```typescript
58
+ // app/api/login/route.ts
59
+ import { withSecureNow } from 'securenow/nextjs-wrapper';
60
+
61
+ export const POST = withSecureNow(async (request: Request) => {
62
+ const body = await request.json();
63
+ // Your logic...
64
+ return Response.json({ success: true });
65
+ });
66
+ ```
67
+
68
+ **That's it!** No middleware.ts needed.
69
+
70
+ 📚 **Full guide:** See `NEXTJS-WRAPPER-APPROACH.md`
71
+
72
+ ---
73
+
74
+ ## ⚠️ Middleware Approach (Use with Caution)
75
+
76
+ ### How It Works
77
+
78
+ Export SecureNow's middleware to capture bodies **before your handlers**:
79
+
80
+ ```typescript
81
+ // middleware.ts
82
+ export { middleware } from 'securenow/nextjs-middleware';
83
+
84
+ export const config = {
85
+ matcher: '/api/:path*',
86
+ };
87
+ ```
88
+
89
+ ### ✅ Pros
90
+
91
+ - One-time setup (no per-route wrapping)
92
+ - Applies to all routes automatically
93
+
94
+ ### ❌ Cons
95
+
96
+ - **Can conflict with NextAuth** and other middleware
97
+ - **May block requests** from reaching handlers
98
+ - **All-or-nothing** - applies to all matched routes
99
+ - **Runs before routing** - can interfere with request flow
100
+ - **May cause "Response body disturbed or locked" errors**
101
+
102
+ ### When to Use
103
+
104
+ - You have no other middleware
105
+ - You want to capture ALL routes
106
+ - You're okay with potential conflicts
107
+ - **Not recommended if you use NextAuth or have complex middleware**
108
+
109
+ ### Known Issues
110
+
111
+ **Conflicts with NextAuth:**
112
+ ```typescript
113
+ // ❌ This can cause conflicts
114
+ export { middleware } from 'securenow/nextjs-middleware';
115
+
116
+ // If you also use NextAuth, you'll need complex middleware composition
117
+ ```
118
+
119
+ **Solution:** Use the wrapper approach instead!
120
+
121
+ 📚 **Full guide:** See `NEXTJS-BODY-CAPTURE.md` (but consider wrapper approach first)
122
+
123
+ ---
124
+
125
+ ## 🔄 Comparison Table
126
+
127
+ | Feature | Wrapper Approach | Middleware Approach |
128
+ |---------|-----------------|---------------------|
129
+ | **Setup complexity** | Per-route wrapping | One-time setup |
130
+ | **Middleware conflicts** | ✅ None | ⚠️ Possible |
131
+ | **NextAuth compatibility** | ✅ Perfect | ❌ Can conflict |
132
+ | **Request blocking** | ✅ Never | ⚠️ Possible |
133
+ | **Control granularity** | ✅ Per-route | ❌ All-or-nothing |
134
+ | **Error impact** | ✅ Isolated | ⚠️ Can block all routes |
135
+ | **Recommended for** | ✅ Most users | ⚠️ Simple apps only |
136
+
137
+ ---
138
+
139
+ ## 🎯 Our Recommendation
140
+
141
+ ### For Most Users (Especially with NextAuth)
142
+
143
+ **Use the Wrapper Approach:**
144
+
145
+ ```typescript
146
+ // middleware.ts - Your auth logic (no securenow!)
147
+ export async function middleware(request) {
148
+ // Just your middleware - no securenow imports
149
+ const token = await getToken({ req: request });
150
+ if (!token) return NextResponse.redirect('/login');
151
+ return NextResponse.next();
152
+ }
153
+
154
+ // app/api/protected/route.ts - Wrap individual routes
155
+ import { withSecureNow } from 'securenow/nextjs-wrapper';
156
+
157
+ export const POST = withSecureNow(async (request: Request) => {
158
+ // Your handler - no conflicts!
159
+ const body = await request.json();
160
+ return Response.json({ success: true });
161
+ });
162
+ ```
163
+
164
+ **Why?**
165
+ - ✅ Zero conflicts
166
+ - ✅ Your middleware stays clean
167
+ - ✅ Per-route control
168
+ - ✅ Never blocks requests
169
+
170
+ ### For Simple Apps (No Other Middleware)
171
+
172
+ **You can use Middleware Approach:**
173
+
174
+ ```typescript
175
+ // middleware.ts
176
+ export { middleware } from 'securenow/nextjs-middleware';
177
+
178
+ export const config = {
179
+ matcher: '/api/:path*',
180
+ };
181
+ ```
182
+
183
+ **Why?**
184
+ - ✅ One-time setup
185
+ - ✅ Auto-applies to all routes
186
+ - ⚠️ But be aware of potential conflicts if you add other middleware later
187
+
188
+ ---
189
+
190
+ ## 📊 Real-World Scenarios
191
+
192
+ ### Scenario 1: NextAuth + SecureNow
193
+
194
+ **❌ Middleware Approach - Can Cause Issues:**
195
+ ```typescript
196
+ // middleware.ts
197
+ import { getToken } from 'next-auth/jwt';
198
+ import { middleware as securenowMiddleware } from 'securenow/nextjs-middleware';
199
+
200
+ export async function middleware(request) {
201
+ // Complex composition needed - prone to conflicts
202
+ await securenowMiddleware(request);
203
+ const token = await getToken({ req: request });
204
+ // ...
205
+ }
206
+ ```
207
+
208
+ **✅ Wrapper Approach - Clean & Safe:**
209
+ ```typescript
210
+ // middleware.ts - Just NextAuth
211
+ export async function middleware(request) {
212
+ const token = await getToken({ req: request });
213
+ if (!token) return NextResponse.redirect('/login');
214
+ return NextResponse.next();
215
+ }
216
+
217
+ // app/api/*/route.ts - Add SecureNow per route
218
+ import { withSecureNow } from 'securenow/nextjs-wrapper';
219
+ export const POST = withSecureNow(handler);
220
+ ```
221
+
222
+ ### Scenario 2: Rate Limiting + SecureNow
223
+
224
+ **❌ Middleware Approach:**
225
+ ```typescript
226
+ // Multiple middleware = conflicts
227
+ ```
228
+
229
+ **✅ Wrapper Approach:**
230
+ ```typescript
231
+ // middleware.ts - Just rate limiting
232
+ export async function middleware(request) {
233
+ await checkRateLimit(request);
234
+ return NextResponse.next();
235
+ }
236
+
237
+ // routes - Add SecureNow
238
+ export const POST = withSecureNow(handler);
239
+ ```
240
+
241
+ ### Scenario 3: Simple API (No Other Middleware)
242
+
243
+ **✅ Either Approach Works:**
244
+
245
+ **Option A - Wrapper:**
246
+ ```typescript
247
+ export const POST = withSecureNow(handler);
248
+ ```
249
+
250
+ **Option B - Middleware:**
251
+ ```typescript
252
+ export { middleware } from 'securenow/nextjs-middleware';
253
+ ```
254
+
255
+ Both work fine when you have no other middleware!
256
+
257
+ ---
258
+
259
+ ## 🚀 Migration Guide
260
+
261
+ ### From Middleware to Wrapper
262
+
263
+ **Before:**
264
+ ```typescript
265
+ // middleware.ts
266
+ export { middleware } from 'securenow/nextjs-middleware';
267
+ export const config = { matcher: '/api/:path*' };
268
+ ```
269
+
270
+ **After:**
271
+ ```typescript
272
+ // middleware.ts - Delete securenow import!
273
+ // (Keep your other middleware like NextAuth)
274
+
275
+ // app/api/login/route.ts
276
+ import { withSecureNow } from 'securenow/nextjs-wrapper';
277
+ export const POST = withSecureNow(async (request) => {
278
+ // Your handler
279
+ });
280
+
281
+ // app/api/register/route.ts
282
+ import { withSecureNow } from 'securenow/nextjs-wrapper';
283
+ export const POST = withSecureNow(async (request) => {
284
+ // Your handler
285
+ });
286
+ ```
287
+
288
+ **Result:** No more conflicts! 🎉
289
+
290
+ ---
291
+
292
+ ## ✅ Summary
293
+
294
+ ### Quick Decision Guide
295
+
296
+ **Do you have NextAuth or other middleware?**
297
+ - Yes → Use **Wrapper Approach** ✅
298
+ - No → Either works, but wrapper is safer
299
+
300
+ **Do you want per-route control?**
301
+ - Yes → Use **Wrapper Approach** ✅
302
+ - No → Middleware works
303
+
304
+ **Do you prioritize zero conflicts?**
305
+ - Yes → Use **Wrapper Approach** ✅
306
+ - Not critical → Middleware works
307
+
308
+ **Do you experience "Response body disturbed" errors?**
309
+ - Yes → Switch to **Wrapper Approach** ✅
310
+
311
+ ### Bottom Line
312
+
313
+ **For 90% of users:** Use the **Wrapper Approach**
314
+
315
+ It's safer, more flexible, and conflict-free!
316
+
317
+ 📚 **Full documentation:**
318
+ - Wrapper: `NEXTJS-WRAPPER-APPROACH.md`
319
+ - Middleware: `NEXTJS-BODY-CAPTURE.md`
320
+
321
+
322
+
323
+
@@ -213,7 +213,7 @@ your-nextjs-app/
213
213
  -d '{"username":"test","password":"secret123"}'
214
214
  ```
215
215
 
216
- 4. **Check SigNoz:**
216
+ 4. **Check SecureNow:**
217
217
  - Find the `/api/test` trace
218
218
  - Look for `http.request.body` attribute
219
219
  - Verify password shows `[REDACTED]`
@@ -259,7 +259,7 @@ export const config = {
259
259
  ```bash
260
260
  # Required
261
261
  SECURENOW_APPID=my-nextjs-app
262
- SECURENOW_INSTANCE=http://your-signoz:4318
262
+ SECURENOW_INSTANCE=http://your-otlp-backend:4318
263
263
 
264
264
  # Optional: Enable body capture
265
265
  SECURENOW_CAPTURE_BODY=1
@@ -1,6 +1,6 @@
1
1
  # SecureNow for Next.js - Complete Integration Guide
2
2
 
3
- Send traces and logs from your Next.js app to SigNoz (or any OpenTelemetry-compatible backend) in under 2 minutes.
3
+ Send traces and logs from your Next.js app to SecureNow or any OTLP-compatible backend in under 2 minutes.
4
4
 
5
5
  ## 🚀 Quick Start (2 Simple Steps!)
6
6
 
@@ -27,11 +27,11 @@ pnpm add securenow
27
27
  Edit the `.env.local` file that was created:
28
28
 
29
29
  ```bash
30
- # Required: Your app name (shows up in SigNoz)
30
+ # Required: Your app name (shows up in SecureNow)
31
31
  SECURENOW_APPID=my-nextjs-app
32
32
 
33
- # Required: Your SigNoz server endpoint
34
- SECURENOW_INSTANCE=http://your-signoz-server:4318
33
+ # Required: Your OTLP endpoint
34
+ SECURENOW_INSTANCE=http://your-otlp-backend:4318
35
35
 
36
36
  # Optional: API key for authentication
37
37
  OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key-here"
@@ -155,7 +155,7 @@ See [REQUEST-BODY-CAPTURE.md](./REQUEST-BODY-CAPTURE.md) for full details.
155
155
  SECURENOW_APPID=my-nextjs-app
156
156
 
157
157
  # Optional Configuration
158
- SECURENOW_INSTANCE=http://your-signoz-server:4318
158
+ SECURENOW_INSTANCE=http://your-otlp-backend:4318
159
159
  SECURENOW_NO_UUID=1 # Don't append UUID (useful for dev)
160
160
  OTEL_LOG_LEVEL=info # debug|info|warn|error
161
161
  SECURENOW_DISABLE_INSTRUMENTATIONS=fs,dns # Disable specific instrumentations
@@ -178,7 +178,7 @@ import { registerSecureNow } from 'securenow/nextjs';
178
178
  export function register() {
179
179
  registerSecureNow({
180
180
  serviceName: 'my-nextjs-app',
181
- endpoint: 'http://your-signoz-server:4318',
181
+ endpoint: 'http://your-otlp-backend:4318',
182
182
  noUuid: false,
183
183
  disableInstrumentations: ['fs', 'dns'],
184
184
  headers: {
@@ -243,7 +243,7 @@ COPY . .
243
243
  RUN npm run build
244
244
 
245
245
  ENV SECURENOW_APPID=my-nextjs-app
246
- ENV SECURENOW_INSTANCE=http://signoz:4318
246
+ ENV SECURENOW_INSTANCE=http://otel-collector:4318
247
247
 
248
248
  EXPOSE 3000
249
249
  CMD ["npm", "start"]
@@ -255,7 +255,7 @@ Just set environment variables and run:
255
255
 
256
256
  ```bash
257
257
  export SECURENOW_APPID=my-nextjs-app
258
- export SECURENOW_INSTANCE=http://your-signoz-server:4318
258
+ export SECURENOW_INSTANCE=http://your-otlp-backend:4318
259
259
  npm start
260
260
  ```
261
261
 
@@ -288,14 +288,14 @@ Make sure you're on the latest version:
288
288
  npm install securenow@latest
289
289
  ```
290
290
 
291
- ### Traces not appearing in SigNoz
291
+ ### Traces not appearing in SecureNow
292
292
 
293
293
  1. **Check endpoint:**
294
294
  ```bash
295
- curl http://your-signoz-server:4318/v1/traces
295
+ curl http://your-otlp-backend:4318/v1/traces
296
296
  ```
297
297
 
298
- 2. **Verify connectivity:** Make sure your app can reach SigNoz
298
+ 2. **Verify connectivity:** Make sure your app can reach your OTLP backend (or SecureNow)
299
299
 
300
300
  3. **Check authentication:** If using API keys, verify headers
301
301
 
@@ -311,7 +311,7 @@ SECURENOW_DISABLE_INSTRUMENTATIONS=fs,dns,net
311
311
  ## 📖 Comparison with Other Solutions
312
312
 
313
313
  ### vs. `@vercel/otel`
314
- - ✅ **SecureNow**: Pre-configured for SigNoz, includes auto-instrumentations
314
+ - ✅ **SecureNow**: Pre-configured for OTLP / SecureNow, includes auto-instrumentations
315
315
  - ⚠️ **@vercel/otel**: Requires manual instrumentation setup
316
316
 
317
317
  ### vs. Manual OpenTelemetry Setup
@@ -375,7 +375,7 @@ Check the `examples/` folder for:
375
375
 
376
376
  - **Issues:** [GitHub Issues](https://github.com/your-repo/securenow/issues)
377
377
  - **Documentation:** [Full Documentation](https://your-docs-site.com)
378
- - **SigNoz Docs:** [SigNoz OpenTelemetry Docs](https://signoz.io/docs/)
378
+ - **SecureNow:** [securenow.ai](https://securenow.ai/)
379
379
 
380
380
  ---
381
381
 
@@ -385,5 +385,5 @@ ISC
385
385
 
386
386
  ---
387
387
 
388
- **Made with ❤️ for the Next.js and SigNoz community**
388
+ **Made with ❤️ for the Next.js and SecureNow community**
389
389
 
@@ -59,7 +59,7 @@ Look for:
59
59
  [securenow] ✅ OpenTelemetry started for Next.js
60
60
  ```
61
61
 
62
- Open SigNoz → check for traces from `my-nextjs-app`
62
+ Open SecureNow → check for traces from `my-nextjs-app`
63
63
 
64
64
  ---
65
65