securenow 7.6.7 → 7.6.8
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.
- package/NPM_README.md +13 -13
- package/README.md +21 -37
- package/app-config.js +5 -3
- package/cli/config.js +4 -3
- package/cli/diagnostics.js +54 -15
- package/cli/run.js +40 -11
- package/firewall-only.js +1 -1
- package/mcp/catalog.js +1 -1
- package/nextjs-webpack-config.js +3 -15
- package/nextjs.js +21 -23
- package/nuxt-server-plugin.mjs +20 -10
- package/package.json +33 -34
- package/register.js +1 -1
- package/tracing.js +17 -7
- package/web-vite.mjs +23 -13
- package/CONSUMING-APPS-GUIDE.md +0 -463
- package/docs/ALL-FRAMEWORKS-QUICKSTART.md +0 -1388
- package/docs/API-KEYS-GUIDE.md +0 -278
- package/docs/ARCHITECTURE.md +0 -408
- package/docs/AUTO-BODY-CAPTURE.md +0 -412
- package/docs/AUTO-SETUP-SUMMARY.md +0 -331
- package/docs/AUTO-SETUP.md +0 -419
- package/docs/AUTOMATIC-IP-CAPTURE.md +0 -359
- package/docs/BODY-CAPTURE-FIX.md +0 -261
- package/docs/BODY-CAPTURE-QUICKSTART.md +0 -147
- package/docs/CHANGELOG-NEXTJS.md +0 -235
- package/docs/COMPLETION-REPORT.md +0 -408
- package/docs/CUSTOMER-GUIDE.md +0 -364
- package/docs/EASIEST-SETUP.md +0 -342
- package/docs/ENVIRONMENT-VARIABLES.md +0 -166
- package/docs/ENVIRONMENTS.md +0 -60
- package/docs/EXPRESS-BODY-CAPTURE.md +0 -1028
- package/docs/EXPRESS-SETUP-GUIDE.md +0 -722
- package/docs/FINAL-SOLUTION.md +0 -335
- package/docs/FIREWALL-GUIDE.md +0 -440
- package/docs/IMPLEMENTATION-SUMMARY.md +0 -410
- package/docs/INDEX.md +0 -222
- package/docs/LOGGING-GUIDE.md +0 -704
- package/docs/LOGGING-QUICKSTART.md +0 -221
- package/docs/MCP-GUIDE.md +0 -58
- package/docs/NEXTJS-BODY-CAPTURE-COMPARISON.md +0 -323
- package/docs/NEXTJS-BODY-CAPTURE.md +0 -368
- package/docs/NEXTJS-GUIDE.md +0 -392
- package/docs/NEXTJS-QUICKSTART.md +0 -83
- package/docs/NEXTJS-SETUP-COMPLETE.md +0 -795
- package/docs/NEXTJS-WEBPACK-WARNINGS.md +0 -267
- package/docs/NEXTJS-WRAPPER-APPROACH.md +0 -414
- package/docs/NUXT-GUIDE.md +0 -173
- package/docs/QUICKSTART-BODY-CAPTURE.md +0 -293
- package/docs/REDACTION-EXAMPLES.md +0 -484
- package/docs/REQUEST-BODY-CAPTURE.md +0 -587
- package/docs/SOLUTION-SUMMARY.md +0 -312
- package/docs/VERCEL-OTEL-MIGRATION.md +0 -255
- package/examples/README.md +0 -265
- package/examples/express-with-logging.js +0 -137
- package/examples/instrumentation-with-auto-capture.ts +0 -41
- package/examples/next.config.js +0 -37
- package/examples/nextjs-api-route-with-body-capture.ts +0 -54
- package/examples/nextjs-env-example.txt +0 -32
- package/examples/nextjs-instrumentation.js +0 -36
- package/examples/nextjs-instrumentation.ts +0 -36
- package/examples/nextjs-middleware.js +0 -37
- package/examples/nextjs-middleware.ts +0 -37
- package/examples/nextjs-with-logging-example.md +0 -301
- package/examples/nextjs-with-options.ts +0 -36
- package/examples/test-nextjs-setup.js +0 -70
- package/postinstall.js +0 -296
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
# Next.js Webpack Warnings - Fix Guide
|
|
2
|
-
|
|
3
|
-
## The Problem
|
|
4
|
-
|
|
5
|
-
When using SecureNow with Next.js, you might see webpack warnings like:
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
⚠ Critical dependency: the request of a dependency is an expression
|
|
9
|
-
⚠ Module not found: Can't resolve '@opentelemetry/winston-transport'
|
|
10
|
-
⚠ Module not found: Can't resolve '@opentelemetry/exporter-jaeger'
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
**Good news:** Your app still works! These are just webpack bundling warnings.
|
|
14
|
-
|
|
15
|
-
**Why it happens:** OpenTelemetry instrumentations use dynamic `require()` statements that webpack can't analyze at build time. This is normal for Node.js server code but Next.js's bundler complains about it.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## ✅ Solution 1: Suppress Warnings (Recommended)
|
|
20
|
-
|
|
21
|
-
Add webpack configuration to suppress these warnings.
|
|
22
|
-
|
|
23
|
-
### Step 1: Update your `next.config.js`
|
|
24
|
-
|
|
25
|
-
```javascript
|
|
26
|
-
const { getSecureNowWebpackConfig } = require('securenow/nextjs-webpack-config');
|
|
27
|
-
|
|
28
|
-
/** @type {import('next').NextConfig} */
|
|
29
|
-
const nextConfig = {
|
|
30
|
-
webpack: (config, options) => {
|
|
31
|
-
return getSecureNowWebpackConfig(config, options);
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
// Optional: Tell Next.js not to bundle OpenTelemetry packages
|
|
35
|
-
serverExternalPackages: [
|
|
36
|
-
'@opentelemetry/sdk-node',
|
|
37
|
-
'@opentelemetry/auto-instrumentations-node',
|
|
38
|
-
],
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
module.exports = nextConfig;
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Step 2: Restart your dev server
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
npm run dev
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
**Done!** No more warnings. ✨
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## ✅ Solution 2: Manual Webpack Config
|
|
55
|
-
|
|
56
|
-
If you already have custom webpack config:
|
|
57
|
-
|
|
58
|
-
```javascript
|
|
59
|
-
/** @type {import('next').NextConfig} */
|
|
60
|
-
const nextConfig = {
|
|
61
|
-
webpack: (config, options) => {
|
|
62
|
-
if (options.isServer) {
|
|
63
|
-
// Suppress OpenTelemetry warnings
|
|
64
|
-
config.ignoreWarnings = config.ignoreWarnings || [];
|
|
65
|
-
config.ignoreWarnings.push(
|
|
66
|
-
{
|
|
67
|
-
module: /@opentelemetry\/instrumentation/,
|
|
68
|
-
message: /Critical dependency/,
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
module: /@opentelemetry/,
|
|
72
|
-
message: /Module not found.*winston-transport/,
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
module: /@opentelemetry/,
|
|
76
|
-
message: /Module not found.*exporter-jaeger/,
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Your other webpack config
|
|
82
|
-
return config;
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
module.exports = nextConfig;
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
## ✅ Solution 3: Disable Problematic Instrumentations
|
|
92
|
-
|
|
93
|
-
If you don't need certain instrumentations, disable them:
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
96
|
-
// instrumentation.ts
|
|
97
|
-
import { registerSecureNow } from 'securenow/nextjs';
|
|
98
|
-
|
|
99
|
-
export function register() {
|
|
100
|
-
registerSecureNow({
|
|
101
|
-
disableInstrumentations: [
|
|
102
|
-
'winston', // Winston logger (optional)
|
|
103
|
-
'bunyan', // Bunyan logger (optional)
|
|
104
|
-
'pino', // Pino logger (optional)
|
|
105
|
-
'fs', // File system (too noisy)
|
|
106
|
-
],
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
## 📋 Understanding the Warnings
|
|
114
|
-
|
|
115
|
-
### "Critical dependency" warnings
|
|
116
|
-
|
|
117
|
-
**What it means:** OpenTelemetry uses `require(moduleName)` where `moduleName` is a variable. Webpack can't analyze this statically.
|
|
118
|
-
|
|
119
|
-
**Is it a problem?** No! These modules are only loaded at runtime on the server, not in the browser.
|
|
120
|
-
|
|
121
|
-
**Solution:** Suppress the warnings using webpack config.
|
|
122
|
-
|
|
123
|
-
### "Module not found" warnings
|
|
124
|
-
|
|
125
|
-
**What it means:** Some instrumentations have optional peer dependencies that aren't installed.
|
|
126
|
-
|
|
127
|
-
**Is it a problem?** No! These are optional. If you're not using Winston logging or Jaeger exporter, you don't need them.
|
|
128
|
-
|
|
129
|
-
**Solution:** Either:
|
|
130
|
-
1. Suppress the warnings (recommended)
|
|
131
|
-
2. Disable those instrumentations
|
|
132
|
-
3. Install the missing packages (only if you use them)
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
## 🔧 Advanced: serverExternalPackages
|
|
137
|
-
|
|
138
|
-
For Next.js 13+, you can tell Next.js not to bundle certain packages:
|
|
139
|
-
|
|
140
|
-
```javascript
|
|
141
|
-
const nextConfig = {
|
|
142
|
-
serverExternalPackages: [
|
|
143
|
-
'@opentelemetry/sdk-node',
|
|
144
|
-
'@opentelemetry/auto-instrumentations-node',
|
|
145
|
-
'@opentelemetry/instrumentation',
|
|
146
|
-
],
|
|
147
|
-
};
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
This tells Next.js to leave these packages as `require()` statements instead of bundling them.
|
|
151
|
-
|
|
152
|
-
---
|
|
153
|
-
|
|
154
|
-
## 📦 Complete Example
|
|
155
|
-
|
|
156
|
-
Here's a complete `next.config.js` that handles everything:
|
|
157
|
-
|
|
158
|
-
```javascript
|
|
159
|
-
const { getSecureNowWebpackConfig } = require('securenow/nextjs-webpack-config');
|
|
160
|
-
|
|
161
|
-
/** @type {import('next').NextConfig} */
|
|
162
|
-
const nextConfig = {
|
|
163
|
-
// Suppress warnings
|
|
164
|
-
webpack: (config, options) => {
|
|
165
|
-
return getSecureNowWebpackConfig(config, options);
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
// Don't bundle OpenTelemetry
|
|
169
|
-
serverExternalPackages: [
|
|
170
|
-
'@opentelemetry/sdk-node',
|
|
171
|
-
'@opentelemetry/auto-instrumentations-node',
|
|
172
|
-
],
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
module.exports = nextConfig;
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
## ❓ FAQ
|
|
181
|
-
|
|
182
|
-
### Q: Will these warnings affect my production build?
|
|
183
|
-
|
|
184
|
-
**A:** No. Your production build will work fine. These are just webpack warnings, not errors.
|
|
185
|
-
|
|
186
|
-
### Q: Should I be concerned about these warnings?
|
|
187
|
-
|
|
188
|
-
**A:** No. They're expected when using Node.js instrumentation in Next.js. Just suppress them using the webpack config.
|
|
189
|
-
|
|
190
|
-
### Q: Do I need to install the missing packages?
|
|
191
|
-
|
|
192
|
-
**A:** Only if you're actually using them. For example:
|
|
193
|
-
- `@opentelemetry/winston-transport` - only if you use Winston logger
|
|
194
|
-
- `@opentelemetry/exporter-jaeger` - only if you want to export to Jaeger
|
|
195
|
-
|
|
196
|
-
### Q: Why doesn't SecureNow bundle these packages?
|
|
197
|
-
|
|
198
|
-
**A:** OpenTelemetry instrumentations are designed for Node.js server environments and use features that don't work in bundled code (like dynamic requires and module patching).
|
|
199
|
-
|
|
200
|
-
### Q: Can I use SecureNow without these warnings?
|
|
201
|
-
|
|
202
|
-
**A:** Yes! Use the webpack config provided above to suppress them.
|
|
203
|
-
|
|
204
|
-
---
|
|
205
|
-
|
|
206
|
-
## 🎯 Quick Fix (Copy-Paste)
|
|
207
|
-
|
|
208
|
-
**Just add this to your `next.config.js`:**
|
|
209
|
-
|
|
210
|
-
```javascript
|
|
211
|
-
const { getSecureNowWebpackConfig } = require('securenow/nextjs-webpack-config');
|
|
212
|
-
|
|
213
|
-
module.exports = {
|
|
214
|
-
webpack: getSecureNowWebpackConfig,
|
|
215
|
-
};
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
**That's it!** ✅
|
|
219
|
-
|
|
220
|
-
---
|
|
221
|
-
|
|
222
|
-
## 🆘 Still Having Issues?
|
|
223
|
-
|
|
224
|
-
If you're still seeing warnings after applying the fix:
|
|
225
|
-
|
|
226
|
-
1. **Restart your dev server completely**
|
|
227
|
-
```bash
|
|
228
|
-
# Stop the server (Ctrl+C)
|
|
229
|
-
# Clear Next.js cache
|
|
230
|
-
rm -rf .next
|
|
231
|
-
# Start again
|
|
232
|
-
npm run dev
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
2. **Check your Next.js version**
|
|
236
|
-
```bash
|
|
237
|
-
npm list next
|
|
238
|
-
```
|
|
239
|
-
- Next.js 15+ works best
|
|
240
|
-
- Next.js 14 and below need `experimentalInstrumentationHook: true`
|
|
241
|
-
|
|
242
|
-
3. **Verify webpack config is loading**
|
|
243
|
-
- Check that `next.config.js` is in your project root
|
|
244
|
-
- Make sure it's a `.js` file (not `.mjs` or `.ts`)
|
|
245
|
-
|
|
246
|
-
4. **Check for conflicting webpack config**
|
|
247
|
-
- If you have other webpack plugins, they might conflict
|
|
248
|
-
- Try the SecureNow config alone first
|
|
249
|
-
|
|
250
|
-
---
|
|
251
|
-
|
|
252
|
-
## 📚 More Help
|
|
253
|
-
|
|
254
|
-
- [Next.js Webpack Documentation](https://nextjs.org/docs/app/api-reference/next-config-js/webpack)
|
|
255
|
-
- [OpenTelemetry Next.js Guide](./NEXTJS-GUIDE.md)
|
|
256
|
-
- [SecureNow Documentation](./README.md)
|
|
257
|
-
|
|
258
|
-
---
|
|
259
|
-
|
|
260
|
-
**TL;DR:** Add webpack config to suppress warnings. Your app works fine, the warnings are just noise from webpack trying to analyze Node.js server code.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
# ✅ Next.js Body Capture - Non-Invasive Wrapper Approach
|
|
2
|
-
|
|
3
|
-
## 🎯 The Problem with Middleware
|
|
4
|
-
|
|
5
|
-
**Middleware runs BEFORE your handlers** and can:
|
|
6
|
-
- ❌ Conflict with NextAuth and other middleware
|
|
7
|
-
- ❌ Block requests from reaching handlers
|
|
8
|
-
- ❌ Cause "Response body disturbed or locked" errors
|
|
9
|
-
- ❌ Interfere with routing
|
|
10
|
-
|
|
11
|
-
## ✅ The Solution: Handler Wrappers
|
|
12
|
-
|
|
13
|
-
**Wrappers run INSIDE your handlers** and:
|
|
14
|
-
- ✅ Never conflict with middleware
|
|
15
|
-
- ✅ Never block requests
|
|
16
|
-
- ✅ Run after all routing is complete
|
|
17
|
-
- ✅ Optional per-route (only wrap what you need)
|
|
18
|
-
- ✅ Non-invasive and safe
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## 🚀 Quick Start
|
|
23
|
-
|
|
24
|
-
### Step 1: Enable in Environment
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
# .env.local
|
|
28
|
-
SECURENOW_CAPTURE_BODY=1
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### Step 2: Wrap Your API Routes
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
// app/api/login/route.ts
|
|
35
|
-
import { withSecureNow } from 'securenow/nextjs-wrapper';
|
|
36
|
-
|
|
37
|
-
export const POST = withSecureNow(async (request: Request) => {
|
|
38
|
-
const body = await request.json();
|
|
39
|
-
// Your handler code...
|
|
40
|
-
return Response.json({ success: true });
|
|
41
|
-
});
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
**That's it!** Body is captured with sensitive fields redacted.
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## 📊 How It Works
|
|
49
|
-
|
|
50
|
-
### Traditional Middleware (Problematic)
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
Request → Middleware (reads body) → Conflicts → Handler (may not receive)
|
|
54
|
-
❌ Can block/interfere
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Wrapper Approach (Safe)
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
Request → All Middleware → Routing → Handler (your code)
|
|
61
|
-
↓
|
|
62
|
-
Wrapper captures body in background
|
|
63
|
-
↓
|
|
64
|
-
Response returned
|
|
65
|
-
✅ Never blocks or interferes
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
**Key difference:** The wrapper runs INSIDE your handler, not before it!
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
## 🎓 Usage Examples
|
|
73
|
-
|
|
74
|
-
### Basic Usage
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
import { withSecureNow } from 'securenow/nextjs-wrapper';
|
|
78
|
-
|
|
79
|
-
export const POST = withSecureNow(async (request: Request) => {
|
|
80
|
-
const data = await request.json();
|
|
81
|
-
return Response.json({ received: data });
|
|
82
|
-
});
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### With NextAuth (No Conflicts!)
|
|
86
|
-
|
|
87
|
-
```typescript
|
|
88
|
-
// middleware.ts - Your auth middleware (no securenow here!)
|
|
89
|
-
import { getToken } from 'next-auth/jwt';
|
|
90
|
-
|
|
91
|
-
export async function middleware(request) {
|
|
92
|
-
// Just your auth logic - no securenow interference
|
|
93
|
-
const token = await getToken({ req: request });
|
|
94
|
-
if (!token) {
|
|
95
|
-
return NextResponse.redirect('/login');
|
|
96
|
-
}
|
|
97
|
-
return NextResponse.next();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// app/api/protected/route.ts - Wrap individual routes
|
|
101
|
-
import { withSecureNow } from 'securenow/nextjs-wrapper';
|
|
102
|
-
|
|
103
|
-
export const POST = withSecureNow(async (request: Request) => {
|
|
104
|
-
// This runs AFTER middleware, so no conflicts!
|
|
105
|
-
const body = await request.json();
|
|
106
|
-
return Response.json({ success: true });
|
|
107
|
-
});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### Selective Wrapping
|
|
111
|
-
|
|
112
|
-
```typescript
|
|
113
|
-
import { withSecureNow } from 'securenow/nextjs-wrapper';
|
|
114
|
-
|
|
115
|
-
// Capture body for sensitive routes
|
|
116
|
-
export const POST = withSecureNow(async (request: Request) => {
|
|
117
|
-
const body = await request.json();
|
|
118
|
-
return Response.json({ success: true });
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// Don't capture for other routes
|
|
122
|
-
export async function GET(request: Request) {
|
|
123
|
-
return Response.json({ data: 'public' });
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### With Context (Next.js 14+)
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
import { withSecureNow } from 'securenow/nextjs-wrapper';
|
|
131
|
-
|
|
132
|
-
export const POST = withSecureNow(async (
|
|
133
|
-
request: Request,
|
|
134
|
-
context: { params: { id: string } }
|
|
135
|
-
) => {
|
|
136
|
-
const body = await request.json();
|
|
137
|
-
const { id } = context.params;
|
|
138
|
-
return Response.json({ id, body });
|
|
139
|
-
});
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Pages Router (API Routes)
|
|
143
|
-
|
|
144
|
-
```typescript
|
|
145
|
-
import { withSecureNow } from 'securenow/nextjs-wrapper';
|
|
146
|
-
|
|
147
|
-
async function handler(req, res) {
|
|
148
|
-
if (req.method === 'POST') {
|
|
149
|
-
// Your logic
|
|
150
|
-
res.json({ success: true });
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export default withSecureNow(handler);
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
|
|
159
|
-
## 🔒 Security Features
|
|
160
|
-
|
|
161
|
-
### Automatic Redaction
|
|
162
|
-
|
|
163
|
-
**20+ sensitive fields redacted automatically:**
|
|
164
|
-
```
|
|
165
|
-
password, passwd, pwd, secret, token, api_key, apikey,
|
|
166
|
-
access_token, auth, credentials, card, cvv, cvc, ssn, pin
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
**Example:**
|
|
170
|
-
```typescript
|
|
171
|
-
// Request body:
|
|
172
|
-
{ "username": "john", "password": "secret123" }
|
|
173
|
-
|
|
174
|
-
// Captured in trace:
|
|
175
|
-
{ "username": "john", "password": "[REDACTED]" }
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### Custom Sensitive Fields
|
|
179
|
-
|
|
180
|
-
```bash
|
|
181
|
-
# .env.local
|
|
182
|
-
SECURENOW_SENSITIVE_FIELDS=email,phone,address
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### Size Limits
|
|
186
|
-
|
|
187
|
-
```bash
|
|
188
|
-
# .env.local
|
|
189
|
-
SECURENOW_MAX_BODY_SIZE=20480 # 20KB (default: 10KB)
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
---
|
|
193
|
-
|
|
194
|
-
## ⚡ Performance
|
|
195
|
-
|
|
196
|
-
**Non-blocking design:**
|
|
197
|
-
- Body capture runs in background
|
|
198
|
-
- Handler returns immediately
|
|
199
|
-
- < 1ms overhead
|
|
200
|
-
- Fails silently (never breaks your app)
|
|
201
|
-
|
|
202
|
-
**Overhead comparison:**
|
|
203
|
-
```
|
|
204
|
-
Without wrapper: 0ms baseline
|
|
205
|
-
With wrapper: < 1ms (async capture)
|
|
206
|
-
Your handler logic: Unchanged
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
---
|
|
210
|
-
|
|
211
|
-
## 🎯 When to Use
|
|
212
|
-
|
|
213
|
-
### ✅ Use Wrapper When:
|
|
214
|
-
- You want body capture on specific routes
|
|
215
|
-
- You have NextAuth or other middleware
|
|
216
|
-
- You want zero conflicts
|
|
217
|
-
- You want per-route control
|
|
218
|
-
|
|
219
|
-
### ❌ Don't Use When:
|
|
220
|
-
- You don't need body capture
|
|
221
|
-
- You only want basic tracing (already included!)
|
|
222
|
-
|
|
223
|
-
**Remember:** Body capture is OPTIONAL. You get full tracing without it!
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## 📝 Complete Setup
|
|
228
|
-
|
|
229
|
-
### 1. instrumentation.ts (Required for all tracing)
|
|
230
|
-
|
|
231
|
-
```typescript
|
|
232
|
-
import { registerSecureNow } from 'securenow/nextjs';
|
|
233
|
-
|
|
234
|
-
export function register() {
|
|
235
|
-
registerSecureNow();
|
|
236
|
-
}
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
### 2. .env.local
|
|
240
|
-
|
|
241
|
-
```bash
|
|
242
|
-
# Required
|
|
243
|
-
SECURENOW_APPID=my-nextjs-app
|
|
244
|
-
SECURENOW_INSTANCE=http://otel-collector:4318
|
|
245
|
-
|
|
246
|
-
# Optional: Enable body capture
|
|
247
|
-
SECURENOW_CAPTURE_BODY=1
|
|
248
|
-
SECURENOW_MAX_BODY_SIZE=10240
|
|
249
|
-
SECURENOW_SENSITIVE_FIELDS=custom_field
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
### 3. API Routes (Optional - only for body capture)
|
|
253
|
-
|
|
254
|
-
```typescript
|
|
255
|
-
import { withSecureNow } from 'securenow/nextjs-wrapper';
|
|
256
|
-
|
|
257
|
-
export const POST = withSecureNow(async (request: Request) => {
|
|
258
|
-
const body = await request.json();
|
|
259
|
-
return Response.json({ success: true });
|
|
260
|
-
});
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
### 4. middleware.ts (Your auth logic - no securenow!)
|
|
264
|
-
|
|
265
|
-
```typescript
|
|
266
|
-
// Just your regular middleware - no securenow imports needed!
|
|
267
|
-
import { getToken } from 'next-auth/jwt';
|
|
268
|
-
|
|
269
|
-
export async function middleware(request) {
|
|
270
|
-
// Your auth logic
|
|
271
|
-
const token = await getToken({ req: request });
|
|
272
|
-
if (!token) return NextResponse.redirect('/login');
|
|
273
|
-
return NextResponse.next();
|
|
274
|
-
}
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
---
|
|
278
|
-
|
|
279
|
-
## 🎉 Benefits
|
|
280
|
-
|
|
281
|
-
### No Middleware Conflicts
|
|
282
|
-
- ✅ Works with NextAuth
|
|
283
|
-
- ✅ Works with any middleware
|
|
284
|
-
- ✅ Never interferes with routing
|
|
285
|
-
- ✅ Runs after all middleware completes
|
|
286
|
-
|
|
287
|
-
### Non-Blocking
|
|
288
|
-
- ✅ Captures in background
|
|
289
|
-
- ✅ Handler returns immediately
|
|
290
|
-
- ✅ Never delays responses
|
|
291
|
-
- ✅ Fails silently
|
|
292
|
-
|
|
293
|
-
### Flexible
|
|
294
|
-
- ✅ Per-route control
|
|
295
|
-
- ✅ Wrap only what you need
|
|
296
|
-
- ✅ Easy to add/remove
|
|
297
|
-
- ✅ Works with App Router & Pages Router
|
|
298
|
-
|
|
299
|
-
### Safe
|
|
300
|
-
- ✅ Uses request.clone() (doesn't consume original)
|
|
301
|
-
- ✅ Error handling (never crashes app)
|
|
302
|
-
- ✅ Size limits (prevents memory issues)
|
|
303
|
-
- ✅ Automatic redaction (protects sensitive data)
|
|
304
|
-
|
|
305
|
-
---
|
|
306
|
-
|
|
307
|
-
## ❓ FAQ
|
|
308
|
-
|
|
309
|
-
### Q: Do I need to change my middleware?
|
|
310
|
-
|
|
311
|
-
**A:** No! Your middleware stays exactly as-is. The wrapper runs inside your handlers, not in middleware.
|
|
312
|
-
|
|
313
|
-
### Q: Will this conflict with NextAuth?
|
|
314
|
-
|
|
315
|
-
**A:** No! NextAuth runs in middleware, this runs in handlers. They never interact.
|
|
316
|
-
|
|
317
|
-
### Q: What if I don't want body capture on all routes?
|
|
318
|
-
|
|
319
|
-
**A:** Only wrap the routes you want! Other routes still get traced, just no body capture.
|
|
320
|
-
|
|
321
|
-
### Q: Does this block my requests?
|
|
322
|
-
|
|
323
|
-
**A:** No! The capture runs asynchronously in the background.
|
|
324
|
-
|
|
325
|
-
### Q: What happens if capture fails?
|
|
326
|
-
|
|
327
|
-
**A:** It fails silently. Your handler always executes normally.
|
|
328
|
-
|
|
329
|
-
### Q: Can I use both middleware and wrapper?
|
|
330
|
-
|
|
331
|
-
**A:** Use wrapper for Next.js (safe). Middleware is kept for backward compatibility but not recommended.
|
|
332
|
-
|
|
333
|
-
---
|
|
334
|
-
|
|
335
|
-
## 🎯 Summary
|
|
336
|
-
|
|
337
|
-
### Wrapper Approach (Recommended)
|
|
338
|
-
```typescript
|
|
339
|
-
// ✅ SAFE - Runs inside handler
|
|
340
|
-
import { withSecureNow } from 'securenow/nextjs-wrapper';
|
|
341
|
-
export const POST = withSecureNow(handler);
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
**Benefits:**
|
|
345
|
-
- ✅ No middleware conflicts
|
|
346
|
-
- ✅ No blocking
|
|
347
|
-
- ✅ Per-route control
|
|
348
|
-
- ✅ Works with NextAuth
|
|
349
|
-
|
|
350
|
-
### Middleware Approach (Not Recommended for Next.js)
|
|
351
|
-
```typescript
|
|
352
|
-
// ❌ Can cause conflicts
|
|
353
|
-
export { middleware } from 'securenow/nextjs-middleware';
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
**Issues:**
|
|
357
|
-
- ❌ Conflicts with NextAuth
|
|
358
|
-
- ❌ Can block requests
|
|
359
|
-
- ❌ Runs before routing
|
|
360
|
-
- ❌ All-or-nothing
|
|
361
|
-
|
|
362
|
-
---
|
|
363
|
-
|
|
364
|
-
## 🚀 Migration Guide
|
|
365
|
-
|
|
366
|
-
**If you're using middleware approach:**
|
|
367
|
-
|
|
368
|
-
### Before (Middleware - Problematic)
|
|
369
|
-
```typescript
|
|
370
|
-
// middleware.ts
|
|
371
|
-
import { middleware as securenowMiddleware } from 'securenow/nextjs-middleware';
|
|
372
|
-
export async function middleware(request) {
|
|
373
|
-
await securenowMiddleware(request); // ❌ Can conflict
|
|
374
|
-
// Your auth logic...
|
|
375
|
-
}
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
### After (Wrapper - Safe)
|
|
379
|
-
```typescript
|
|
380
|
-
// middleware.ts - Remove securenow completely!
|
|
381
|
-
export async function middleware(request) {
|
|
382
|
-
// Just your auth logic - no securenow!
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// app/api/*/route.ts - Add wrapper to individual routes
|
|
386
|
-
import { withSecureNow } from 'securenow/nextjs-wrapper';
|
|
387
|
-
export const POST = withSecureNow(async (request) => {
|
|
388
|
-
// Your handler
|
|
389
|
-
});
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
**Result:** Zero conflicts, full control, no blocking!
|
|
393
|
-
|
|
394
|
-
---
|
|
395
|
-
|
|
396
|
-
## ✅ Ready to Use!
|
|
397
|
-
|
|
398
|
-
**The wrapper approach is:**
|
|
399
|
-
- ✅ Production-ready
|
|
400
|
-
- ✅ Conflict-free
|
|
401
|
-
- ✅ Non-invasive
|
|
402
|
-
- ✅ Self-sufficient
|
|
403
|
-
|
|
404
|
-
**Your customers get:**
|
|
405
|
-
- ✅ Full tracing (always)
|
|
406
|
-
- ✅ Optional body capture (per route)
|
|
407
|
-
- ✅ No code changes needed (except wrapping routes)
|
|
408
|
-
- ✅ Works with any middleware
|
|
409
|
-
|
|
410
|
-
**Status: Recommended for all Next.js apps!** 🎊
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|