@j3r3mcdev/oast-server 1.1.10 → 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.10",
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",