@oculum/scanner 1.0.1 → 1.0.3

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 (45) hide show
  1. package/dist/index.d.ts +4 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +60 -5
  4. package/dist/index.js.map +1 -1
  5. package/dist/layer1/entropy.d.ts.map +1 -1
  6. package/dist/layer1/entropy.js +6 -4
  7. package/dist/layer1/entropy.js.map +1 -1
  8. package/dist/layer1/index.d.ts +3 -2
  9. package/dist/layer1/index.d.ts.map +1 -1
  10. package/dist/layer1/index.js +22 -2
  11. package/dist/layer1/index.js.map +1 -1
  12. package/dist/layer2/dangerous-functions.d.ts.map +1 -1
  13. package/dist/layer2/dangerous-functions.js +319 -11
  14. package/dist/layer2/dangerous-functions.js.map +1 -1
  15. package/dist/layer2/index.d.ts +3 -2
  16. package/dist/layer2/index.d.ts.map +1 -1
  17. package/dist/layer2/index.js +22 -2
  18. package/dist/layer2/index.js.map +1 -1
  19. package/dist/layer3/anthropic.d.ts +5 -1
  20. package/dist/layer3/anthropic.d.ts.map +1 -1
  21. package/dist/layer3/anthropic.js +50 -1
  22. package/dist/layer3/anthropic.js.map +1 -1
  23. package/dist/layer3/index.d.ts +3 -1
  24. package/dist/layer3/index.d.ts.map +1 -1
  25. package/dist/layer3/index.js +21 -0
  26. package/dist/layer3/index.js.map +1 -1
  27. package/dist/types.d.ts +25 -0
  28. package/dist/types.d.ts.map +1 -1
  29. package/dist/types.js +40 -0
  30. package/dist/types.js.map +1 -1
  31. package/dist/utils/context-helpers.d.ts +12 -0
  32. package/dist/utils/context-helpers.d.ts.map +1 -1
  33. package/dist/utils/context-helpers.js +40 -0
  34. package/dist/utils/context-helpers.js.map +1 -1
  35. package/package.json +4 -2
  36. package/src/index.ts +75 -5
  37. package/src/layer1/entropy.ts +6 -4
  38. package/src/layer1/index.ts +33 -5
  39. package/src/layer2/__tests__/math-random-enhanced.test.ts +405 -0
  40. package/src/layer2/dangerous-functions.ts +368 -11
  41. package/src/layer2/index.ts +31 -5
  42. package/src/layer3/anthropic.ts +55 -1
  43. package/src/layer3/index.ts +27 -2
  44. package/src/types.ts +59 -0
  45. package/src/utils/context-helpers.ts +40 -0
package/src/types.ts CHANGED
@@ -56,6 +56,61 @@ export interface Vulnerability {
56
56
  originalSeverity?: VulnerabilitySeverity // For downgraded findings, the original severity
57
57
  }
58
58
 
59
+ /**
60
+ * Cancellation token for aborting scans gracefully
61
+ * Allows users to stop long-running scans (Ctrl+C) and get partial results
62
+ */
63
+ export interface CancellationToken {
64
+ /** Whether cancellation has been requested */
65
+ cancelled: boolean
66
+ /** Reason for cancellation (e.g., "User pressed Ctrl+C") */
67
+ reason?: string
68
+ /** Request cancellation */
69
+ cancel(reason?: string): void
70
+ /** Register cleanup callback to run when cancelled */
71
+ onCancel(callback: () => void): void
72
+ }
73
+
74
+ /**
75
+ * Create a new cancellation token
76
+ *
77
+ * @example
78
+ * const token = createCancellationToken()
79
+ * process.on('SIGINT', () => token.cancel('User interrupted'))
80
+ * const result = await runScan(files, repo, { cancellationToken: token })
81
+ */
82
+ export function createCancellationToken(): CancellationToken {
83
+ const cleanupCallbacks: Array<() => void> = []
84
+
85
+ const token: CancellationToken = {
86
+ cancelled: false,
87
+ reason: undefined,
88
+ cancel(reason?: string) {
89
+ if (!token.cancelled) {
90
+ token.cancelled = true
91
+ token.reason = reason
92
+ // Run cleanup callbacks
93
+ cleanupCallbacks.forEach(cb => {
94
+ try {
95
+ cb()
96
+ } catch (e) {
97
+ // Ignore cleanup errors
98
+ }
99
+ })
100
+ }
101
+ },
102
+ onCancel(callback) {
103
+ if (token.cancelled) {
104
+ callback() // Already cancelled, run immediately
105
+ } else {
106
+ cleanupCallbacks.push(callback)
107
+ }
108
+ }
109
+ }
110
+
111
+ return token
112
+ }
113
+
59
114
  export interface ScanFile {
60
115
  path: string
61
116
  content: string
@@ -107,6 +162,10 @@ export interface ScanResult {
107
162
  cacheReadTokens: number
108
163
  cacheHitRate: number
109
164
  }
165
+
166
+ // Cancellation metadata
167
+ cancelled?: boolean // true if scan was cancelled by user
168
+ cancelReason?: string // Reason for cancellation (e.g., "User pressed Ctrl+C")
110
169
  }
111
170
 
112
171
  export interface ScanProgress {
@@ -201,6 +201,46 @@ export function isClientBundledFile(filePath: string): boolean {
201
201
  return clientPatterns.some(pattern => pattern.test(filePath))
202
202
  }
203
203
 
204
+ /**
205
+ * Check if file is a seed or data generation file
206
+ * These files generate test/demo data and Math.random() usage is acceptable
207
+ * Used to reduce false positives for Math.random() detection
208
+ */
209
+ export function isSeedOrDataGenFile(filePath: string): boolean {
210
+ const patterns = [
211
+ /\/seed\//i,
212
+ /\/seeds\//i,
213
+ /seed-database\.(ts|js)$/i,
214
+ /\/seeder\./i,
215
+ /datacreator\.(ts|js)$/i,
216
+ /\/data\/.*creator/i,
217
+ /\/fixtures\//i,
218
+ /\.fixture\./i,
219
+ /\/generators?\//i,
220
+ /\/factories\//i,
221
+ /factory\.(ts|js)$/i,
222
+ ]
223
+ return patterns.some(p => p.test(filePath))
224
+ }
225
+
226
+ /**
227
+ * Check if file is educational/intentional vulnerability code
228
+ * These files (e.g., OWASP Juice Shop) contain intentional vulnerabilities for training
229
+ * Should be skipped entirely to avoid false positives
230
+ */
231
+ export function isEducationalVulnerabilityFile(filePath: string): boolean {
232
+ const patterns = [
233
+ /\/insecurity\.(ts|js)$/i,
234
+ /\/vulnerable\.(ts|js)$/i,
235
+ /\/intentionally-vulnerable/i,
236
+ /\/security-examples?\//i,
237
+ /\/vuln-examples?\//i,
238
+ /\/challenge-\d+/i, // OWASP Juice Shop challenges
239
+ /\/exploit-examples?\//i,
240
+ ]
241
+ return patterns.some(p => p.test(filePath))
242
+ }
243
+
204
244
  // ============================================================================
205
245
  // Code Line Context Detection
206
246
  // ============================================================================