securenow 7.6.6 → 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.
Files changed (68) 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/firewall.js +88 -57
  9. package/mcp/catalog.js +1 -1
  10. package/nextjs-webpack-config.js +3 -15
  11. package/nextjs.js +21 -23
  12. package/nuxt-server-plugin.mjs +20 -10
  13. package/package.json +33 -34
  14. package/register.js +1 -1
  15. package/tracing.js +17 -7
  16. package/web-vite.mjs +23 -13
  17. package/CONSUMING-APPS-GUIDE.md +0 -463
  18. package/docs/ALL-FRAMEWORKS-QUICKSTART.md +0 -1388
  19. package/docs/API-KEYS-GUIDE.md +0 -278
  20. package/docs/ARCHITECTURE.md +0 -408
  21. package/docs/AUTO-BODY-CAPTURE.md +0 -412
  22. package/docs/AUTO-SETUP-SUMMARY.md +0 -331
  23. package/docs/AUTO-SETUP.md +0 -419
  24. package/docs/AUTOMATIC-IP-CAPTURE.md +0 -359
  25. package/docs/BODY-CAPTURE-FIX.md +0 -261
  26. package/docs/BODY-CAPTURE-QUICKSTART.md +0 -147
  27. package/docs/CHANGELOG-NEXTJS.md +0 -235
  28. package/docs/COMPLETION-REPORT.md +0 -408
  29. package/docs/CUSTOMER-GUIDE.md +0 -364
  30. package/docs/EASIEST-SETUP.md +0 -342
  31. package/docs/ENVIRONMENT-VARIABLES.md +0 -166
  32. package/docs/ENVIRONMENTS.md +0 -60
  33. package/docs/EXPRESS-BODY-CAPTURE.md +0 -1028
  34. package/docs/EXPRESS-SETUP-GUIDE.md +0 -722
  35. package/docs/FINAL-SOLUTION.md +0 -335
  36. package/docs/FIREWALL-GUIDE.md +0 -440
  37. package/docs/IMPLEMENTATION-SUMMARY.md +0 -410
  38. package/docs/INDEX.md +0 -222
  39. package/docs/LOGGING-GUIDE.md +0 -704
  40. package/docs/LOGGING-QUICKSTART.md +0 -221
  41. package/docs/MCP-GUIDE.md +0 -58
  42. package/docs/NEXTJS-BODY-CAPTURE-COMPARISON.md +0 -323
  43. package/docs/NEXTJS-BODY-CAPTURE.md +0 -368
  44. package/docs/NEXTJS-GUIDE.md +0 -392
  45. package/docs/NEXTJS-QUICKSTART.md +0 -83
  46. package/docs/NEXTJS-SETUP-COMPLETE.md +0 -795
  47. package/docs/NEXTJS-WEBPACK-WARNINGS.md +0 -267
  48. package/docs/NEXTJS-WRAPPER-APPROACH.md +0 -414
  49. package/docs/NUXT-GUIDE.md +0 -173
  50. package/docs/QUICKSTART-BODY-CAPTURE.md +0 -293
  51. package/docs/REDACTION-EXAMPLES.md +0 -484
  52. package/docs/REQUEST-BODY-CAPTURE.md +0 -587
  53. package/docs/SOLUTION-SUMMARY.md +0 -312
  54. package/docs/VERCEL-OTEL-MIGRATION.md +0 -255
  55. package/examples/README.md +0 -265
  56. package/examples/express-with-logging.js +0 -137
  57. package/examples/instrumentation-with-auto-capture.ts +0 -41
  58. package/examples/next.config.js +0 -37
  59. package/examples/nextjs-api-route-with-body-capture.ts +0 -54
  60. package/examples/nextjs-env-example.txt +0 -32
  61. package/examples/nextjs-instrumentation.js +0 -36
  62. package/examples/nextjs-instrumentation.ts +0 -36
  63. package/examples/nextjs-middleware.js +0 -37
  64. package/examples/nextjs-middleware.ts +0 -37
  65. package/examples/nextjs-with-logging-example.md +0 -301
  66. package/examples/nextjs-with-options.ts +0 -36
  67. package/examples/test-nextjs-setup.js +0 -70
  68. package/postinstall.js +0 -296
package/postinstall.js DELETED
@@ -1,296 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * SecureNow Post-Install Script
6
- *
7
- * Automatically detects Next.js projects and offers to create instrumentation file
8
- */
9
-
10
- const fs = require('fs');
11
- const path = require('path');
12
- const readline = require('readline');
13
-
14
- // Make sure `.securenow/` is in the project's .gitignore so credentials never get committed.
15
- function ensureGitignore() {
16
- try {
17
- // Skip if we're not in an npm install of a user project
18
- // (e.g., securenow's own CI, or nested install under another node_modules).
19
- const cwd = process.cwd();
20
- if (!fs.existsSync(path.join(cwd, 'package.json'))) return;
21
- if (cwd.includes(`${path.sep}node_modules${path.sep}`)) return;
22
-
23
- const gitignorePath = path.join(cwd, '.gitignore');
24
- const entry = '.securenow/';
25
- const header = '# SecureNow local credentials';
26
-
27
- if (fs.existsSync(gitignorePath)) {
28
- const content = fs.readFileSync(gitignorePath, 'utf8');
29
- const alreadyListed = content.split('\n').some((line) => line.trim() === entry);
30
- if (!alreadyListed) {
31
- const prefix = content.endsWith('\n') ? '' : '\n';
32
- fs.appendFileSync(gitignorePath, `${prefix}\n${header}\n${entry}\n`);
33
- }
34
- } else if (fs.existsSync(path.join(cwd, '.git'))) {
35
- // Only create a new .gitignore if this is actually a git repo.
36
- fs.writeFileSync(gitignorePath, `${header}\n${entry}\n`);
37
- }
38
- } catch {
39
- // Non-fatal
40
- }
41
- }
42
-
43
- // Check if we're in a Next.js project
44
- function isNextJsProject() {
45
- try {
46
- const packageJsonPath = path.join(process.cwd(), 'package.json');
47
- if (!fs.existsSync(packageJsonPath)) return false;
48
-
49
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
50
- const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
51
-
52
- return !!deps.next;
53
- } catch (error) {
54
- return false;
55
- }
56
- }
57
-
58
- // Check if instrumentation file already exists
59
- function hasInstrumentationFile() {
60
- const files = [
61
- 'instrumentation.ts',
62
- 'instrumentation.js',
63
- 'src/instrumentation.ts',
64
- 'src/instrumentation.js'
65
- ];
66
-
67
- return files.some(file => fs.existsSync(path.join(process.cwd(), file)));
68
- }
69
-
70
- // Create TypeScript instrumentation file
71
- function createTsInstrumentation(targetPath) {
72
- const content = `import { createRequire } from 'node:module';
73
-
74
- const require = createRequire(import.meta.url);
75
-
76
- export async function register() {
77
- if (process.env.NEXT_RUNTIME !== 'nodejs') return;
78
-
79
- const { registerSecureNow } = require('securenow/nextjs');
80
- registerSecureNow({ captureBody: true });
81
- require('securenow/nextjs-auto-capture');
82
- }
83
- `;
84
-
85
- fs.writeFileSync(targetPath, content, 'utf8');
86
- }
87
-
88
- // Create JavaScript instrumentation file
89
- function createJsInstrumentation(targetPath) {
90
- const content = `import { createRequire } from 'node:module';
91
-
92
- const require = createRequire(import.meta.url);
93
-
94
- export async function register() {
95
- if (process.env.NEXT_RUNTIME !== 'nodejs') return;
96
-
97
- const { registerSecureNow } = require('securenow/nextjs');
98
- registerSecureNow({ captureBody: true });
99
- require('securenow/nextjs-auto-capture');
100
- }
101
- `;
102
-
103
- fs.writeFileSync(targetPath, content, 'utf8');
104
- }
105
-
106
- // Create TypeScript middleware file
107
- function createTsMiddleware(targetPath) {
108
- const content = `// SecureNow Middleware - Automatic Request Body Capture
109
- // This enables capturing JSON, GraphQL, and Form request bodies
110
- // with automatic sensitive field redaction
111
-
112
- export { middleware } from 'securenow/nextjs-middleware';
113
-
114
- export const config = {
115
- matcher: '/api/:path*', // Apply to all API routes
116
- };
117
-
118
- /**
119
- * Bodies are captured with:
120
- * - Automatic redaction of passwords, tokens, cards, etc.
121
- * - Size limits from .securenow/credentials.json
122
- * - JSON, GraphQL, Form data support
123
- */
124
- `;
125
-
126
- fs.writeFileSync(targetPath, content, 'utf8');
127
- }
128
-
129
- // Create JavaScript middleware file
130
- function createJsMiddleware(targetPath) {
131
- const content = `// SecureNow Middleware - Automatic Request Body Capture
132
- // This enables capturing JSON, GraphQL, and Form request bodies
133
- // with automatic sensitive field redaction
134
-
135
- export { middleware } from 'securenow/nextjs-middleware';
136
-
137
- export const config = {
138
- matcher: '/api/:path*', // Apply to all API routes
139
- };
140
-
141
- /**
142
- * Bodies are captured with:
143
- * - Automatic redaction of passwords, tokens, cards, etc.
144
- * - Size limits from .securenow/credentials.json
145
- * - JSON, GraphQL, Form data support
146
- */
147
- `;
148
-
149
- fs.writeFileSync(targetPath, content, 'utf8');
150
- }
151
-
152
- // Create a credentials-file reminder for old callers that still import this helper.
153
- function createEnvTemplate(targetPath) {
154
- const content = `SecureNow no longer needs a .env file for local development.
155
-
156
- Run:
157
- npx securenow login
158
- npx securenow init
159
-
160
- The CLI writes .securenow/credentials.json with the selected app, firewall key,
161
- secure defaults, and explanations for each setting.
162
- `;
163
-
164
- fs.writeFileSync(targetPath, content, 'utf8');
165
- }
166
-
167
- // Check if TypeScript is used
168
- function isTypeScriptProject() {
169
- return fs.existsSync(path.join(process.cwd(), 'tsconfig.json'));
170
- }
171
-
172
- // Main setup function
173
- async function setup() {
174
- // Always make sure .securenow/ is gitignored (cheap, non-destructive).
175
- ensureGitignore();
176
-
177
- // Skip if not in Next.js project
178
- if (!isNextJsProject()) {
179
- console.log('[securenow] Not a Next.js project, skipping auto-setup');
180
- return;
181
- }
182
-
183
- // Skip if instrumentation file already exists
184
- if (hasInstrumentationFile()) {
185
- console.log('[securenow] ✅ Instrumentation file already exists');
186
- return;
187
- }
188
-
189
- console.log('\n┌─────────────────────────────────────────────────┐');
190
- console.log('│ 🎉 SecureNow installed successfully! │');
191
- console.log('│ Next.js project detected │');
192
- console.log('└─────────────────────────────────────────────────┘\n');
193
-
194
- // Check if we're in CI/non-interactive environment
195
- if (process.env.CI || !process.stdin.isTTY) {
196
- console.log('[securenow] ℹ️ Non-interactive environment detected');
197
- console.log('[securenow] 💡 To complete setup, run: npx securenow init');
198
- return;
199
- }
200
-
201
- // Ask user if they want to auto-setup
202
- const rl = readline.createInterface({
203
- input: process.stdin,
204
- output: process.stdout
205
- });
206
-
207
- rl.question('Would you like to automatically create instrumentation file? (Y/n) ', (answer) => {
208
- const shouldCreate = !answer || answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes';
209
-
210
- if (!shouldCreate) {
211
- console.log('\n[securenow] No problem! To setup later, run: npx securenow init');
212
- rl.close();
213
- return;
214
- }
215
-
216
- try {
217
- const useTypeScript = isTypeScriptProject();
218
- const srcExists = fs.existsSync(path.join(process.cwd(), 'src'));
219
-
220
- // Determine file path
221
- const fileName = useTypeScript ? 'instrumentation.ts' : 'instrumentation.js';
222
- const filePath = srcExists
223
- ? path.join(process.cwd(), 'src', fileName)
224
- : path.join(process.cwd(), fileName);
225
-
226
- // Create instrumentation file
227
- if (useTypeScript) {
228
- createTsInstrumentation(filePath);
229
- } else {
230
- createJsInstrumentation(filePath);
231
- }
232
-
233
- console.log(`\n✅ Created ${srcExists ? 'src/' : ''}${fileName}`);
234
-
235
- // Ask about middleware for body capture
236
- rl.question('\nWould you like to enable request body capture? (y/N) ', (middlewareAnswer) => {
237
- const shouldCreateMiddleware = middlewareAnswer && (middlewareAnswer.toLowerCase() === 'y' || middlewareAnswer.toLowerCase() === 'yes');
238
-
239
- if (shouldCreateMiddleware) {
240
- try {
241
- const middlewareName = useTypeScript ? 'middleware.ts' : 'middleware.js';
242
- const middlewarePath = srcExists
243
- ? path.join(process.cwd(), 'src', middlewareName)
244
- : path.join(process.cwd(), middlewareName);
245
-
246
- if (useTypeScript) {
247
- createTsMiddleware(middlewarePath);
248
- } else {
249
- createJsMiddleware(middlewarePath);
250
- }
251
-
252
- console.log(`✅ Created ${srcExists ? 'src/' : ''}${middlewareName}`);
253
- console.log(' → Captures JSON, GraphQL, Form bodies with auto-redaction');
254
- } catch (error) {
255
- console.warn(`⚠️ Could not create middleware: ${error.message}`);
256
- }
257
- }
258
-
259
- console.log('\n┌─────────────────────────────────────────────────┐');
260
- console.log('│ 🚀 Next Steps: │');
261
- console.log('│ │');
262
- console.log('│ 1. Pick your app in the browser: │');
263
- console.log('│ npx securenow login │');
264
- console.log('│ │');
265
- console.log('│ 2. Run your app: npm run dev │');
266
- console.log('│ │');
267
- console.log('│ 3. Check SecureNow for traces! │');
268
- console.log('│ │');
269
- if (shouldCreateMiddleware) {
270
- console.log('│ 📝 Body capture enabled with auto-redaction │');
271
- }
272
- console.log('│ 📚 Full guide: npm docs securenow │');
273
- console.log('└─────────────────────────────────────────────────┘\n');
274
-
275
- rl.close();
276
- });
277
-
278
- } catch (error) {
279
- console.error('\n❌ Failed to create instrumentation file:', error.message);
280
- console.log('💡 You can create it manually or run: npx securenow init');
281
- rl.close();
282
- }
283
- });
284
- }
285
-
286
- // Run setup if this is a new installation (not being installed as a dependency of another package)
287
- if (require.main === module || process.env.npm_config_global !== 'true') {
288
- setup().catch(err => {
289
- console.error('[securenow] Setup error:', err);
290
- });
291
- }
292
-
293
- module.exports = { setup };
294
-
295
-
296
-