@j3r3mcdev/oast-server 1.1.9 → 1.1.11

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.
@@ -12,5 +12,6 @@ export declare class CoreRouter {
12
12
  private hooks;
13
13
  constructor(storage: Storage, options?: RouterOptions);
14
14
  dispatch(event: AnyNormalizedEvent): Promise<void>;
15
+ route(event: AnyNormalizedEvent): Promise<void>;
15
16
  addHook(hook: RouterHook): void;
16
17
  }
@@ -9,11 +9,8 @@ class CoreRouter {
9
9
  this.hooks = options.hooks ?? [];
10
10
  }
11
11
  async dispatch(event) {
12
- // 1. Log
13
12
  this.logger.info(`Event received (${event.type})`, { id: event.id });
14
- // 2. Save
15
13
  await this.storage.save(event);
16
- // 3. Hooks
17
14
  for (const hook of this.hooks) {
18
15
  try {
19
16
  await hook(event);
@@ -23,6 +20,9 @@ class CoreRouter {
23
20
  }
24
21
  }
25
22
  }
23
+ async route(event) {
24
+ return this.dispatch(event);
25
+ }
26
26
  addHook(hook) {
27
27
  this.hooks.push(hook);
28
28
  }
@@ -13,10 +13,15 @@ class SmtpListener {
13
13
  this.logger.info("SMTP Listener started");
14
14
  this.server.onData = async (stream, session, callback) => {
15
15
  let chunks = [];
16
- stream.on("data", (chunk) => {
16
+ const onData = (chunk) => {
17
17
  chunks.push(chunk.toString());
18
- });
19
- stream.on("end", async () => {
18
+ };
19
+ const onEnd = async () => {
20
+ // 🔥 Compatible Node + Jest + mocks
21
+ if (stream.removeListener) {
22
+ stream.removeListener("data", onData);
23
+ stream.removeListener("end", onEnd);
24
+ }
20
25
  const body = chunks.join("");
21
26
  let event;
22
27
  try {
@@ -37,13 +42,22 @@ class SmtpListener {
37
42
  await this.router.dispatch(event);
38
43
  callback(null);
39
44
  }
40
- catch (err) {
41
- callback(new Error("dispatch failed")); // ✔ EXACTEMENT ce que ton test attend
45
+ catch {
46
+ callback(new Error("dispatch failed"));
42
47
  }
43
- });
48
+ // 🔥 Empêche les fuites de stream
49
+ if (stream.destroy) {
50
+ stream.destroy();
51
+ }
52
+ };
53
+ stream.on("data", onData);
54
+ stream.on("end", onEnd);
44
55
  };
45
56
  }
46
57
  async stop() {
58
+ if (this.server) {
59
+ this.server.onData = undefined;
60
+ }
47
61
  if (this.server?.close) {
48
62
  this.server.close();
49
63
  this.logger.info("SMTP Listener stopped");
@@ -46,6 +46,11 @@ export interface RawWebSocketEvent {
46
46
  message: string;
47
47
  raw: any;
48
48
  }
49
+ export interface RawApiEvent {
50
+ ip: string;
51
+ body: any;
52
+ raw: any;
53
+ }
49
54
  export interface NormalizedHttpEvent {
50
55
  id: string;
51
56
  type: "http";
@@ -115,4 +120,14 @@ export interface NormalizedWebSocketEvent {
115
120
  sourceIp: string;
116
121
  message: string;
117
122
  }
118
- export type AnyNormalizedEvent = NormalizedHttpEvent | NormalizedDnsEvent | NormalizedSmtpEvent | NormalizedTcpEvent | NormalizedSsrfEvent | NormalizedWebhookEvent | NormalizedWebSocketEvent;
123
+ export interface NormalizedApiEvent {
124
+ id: string;
125
+ type: "api";
126
+ timestamp: number;
127
+ sourceIp: string;
128
+ request: {
129
+ body: any;
130
+ };
131
+ raw: any;
132
+ }
133
+ export type AnyNormalizedEvent = NormalizedHttpEvent | NormalizedDnsEvent | NormalizedSmtpEvent | NormalizedTcpEvent | NormalizedSsrfEvent | NormalizedWebhookEvent | NormalizedWebSocketEvent | NormalizedApiEvent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@j3r3mcdev/oast-server",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
4
4
  "description": "Modular OAST callback server for security auditing",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,11 +19,17 @@ export class SmtpListener {
19
19
  this.server.onData = async (stream: any, session: any, callback: any) => {
20
20
  let chunks: string[] = [];
21
21
 
22
- stream.on("data", (chunk: any) => {
22
+ const onData = (chunk: any) => {
23
23
  chunks.push(chunk.toString());
24
- });
24
+ };
25
+
26
+ const onEnd = async () => {
27
+ // 🔥 Compatible Node + Jest + mocks
28
+ if (stream.removeListener) {
29
+ stream.removeListener("data", onData);
30
+ stream.removeListener("end", onEnd);
31
+ }
25
32
 
26
- stream.on("end", async () => {
27
33
  const body = chunks.join("");
28
34
 
29
35
  let event;
@@ -44,14 +50,26 @@ export class SmtpListener {
44
50
  try {
45
51
  await this.router.dispatch(event);
46
52
  callback(null);
47
- } catch (err) {
48
- callback(new Error("dispatch failed")); // ✔ EXACTEMENT ce que ton test attend
53
+ } catch {
54
+ callback(new Error("dispatch failed"));
55
+ }
56
+
57
+ // 🔥 Empêche les fuites de stream
58
+ if (stream.destroy) {
59
+ stream.destroy();
49
60
  }
50
- });
61
+ };
62
+
63
+ stream.on("data", onData);
64
+ stream.on("end", onEnd);
51
65
  };
52
66
  }
53
67
 
54
68
  async stop() {
69
+ if (this.server) {
70
+ this.server.onData = undefined;
71
+ }
72
+
55
73
  if (this.server?.close) {
56
74
  this.server.close();
57
75
  this.logger.info("SMTP Listener stopped");
@@ -56,6 +56,12 @@ export interface RawWebSocketEvent {
56
56
  raw: any;
57
57
  }
58
58
 
59
+ export interface RawApiEvent {
60
+ ip: string;
61
+ body: any;
62
+ raw: any;
63
+ }
64
+
59
65
  //
60
66
  // NORMALIZED EVENTS
61
67
  //
@@ -104,6 +110,7 @@ export interface NormalizedTcpEvent {
104
110
  data: string;
105
111
  raw: any;
106
112
  }
113
+
107
114
  export interface NormalizedSsrfEvent {
108
115
  id: string;
109
116
  type: "ssrf";
@@ -134,6 +141,17 @@ export interface NormalizedWebSocketEvent {
134
141
  message: string;
135
142
  }
136
143
 
144
+ export interface NormalizedApiEvent {
145
+ id: string;
146
+ type: "api";
147
+ timestamp: number;
148
+ sourceIp: string;
149
+ request: {
150
+ body: any;
151
+ };
152
+ raw: any;
153
+ }
154
+
137
155
  //
138
156
  // UNION
139
157
  //
@@ -144,4 +162,5 @@ export type AnyNormalizedEvent =
144
162
  | NormalizedTcpEvent
145
163
  | NormalizedSsrfEvent
146
164
  | NormalizedWebhookEvent
147
- | NormalizedWebSocketEvent;
165
+ | NormalizedWebSocketEvent
166
+ | NormalizedApiEvent;