hyperlane-plugin-audit 23.3.1

A tamper-evident SHA-256 hash-chained security audit trail plugin for the Hyperlane framework with bounded in-memory ring-buffer sink, pluggable AuditSink trait, header redaction, and chain integrity verification.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
use super::*;

/// Streaming FIPS 180-4 SHA-256 implementation for zero-allocation audit hashing.
impl AuditSha256 {
    /// Initializes a fresh SHA-256 state.
    ///
    /// # Returns
    ///
    /// - `Self` - Ready incremental hasher.
    #[inline(always)]
    pub(crate) fn new() -> Self {
        Self {
            state: SHA256_H0,
            block: [0u8; 64],
            block_len: 0,
            total_bytes: 0,
        }
    }

    /// Absorbs a single byte into the running SHA-256 state.
    ///
    /// # Arguments
    ///
    /// - `u8` - Input byte.
    #[inline(always)]
    pub(crate) fn update_byte(&mut self, byte: u8) {
        let Self {
            state,
            block,
            block_len,
            total_bytes,
        } = self;
        *total_bytes = total_bytes.wrapping_add(1);
        block[*block_len] = byte;
        *block_len += 1;
        if *block_len == 64 {
            sha256_compress(state, block);
            *block_len = 0;
        }
    }

    /// Absorbs a slice of bytes into the running SHA-256 state.
    ///
    /// # Arguments
    ///
    /// - `&[u8]` - Input byte slice.
    #[inline]
    pub(crate) fn update(&mut self, mut data: &[u8]) {
        if data.is_empty() {
            return;
        }
        let Self {
            state,
            block,
            block_len,
            total_bytes,
        } = self;
        *total_bytes = total_bytes.wrapping_add(data.len() as u64);
        if *block_len > 0 {
            let need: usize = 64 - *block_len;
            if data.len() < need {
                block[*block_len..*block_len + data.len()].copy_from_slice(data);
                *block_len += data.len();
                return;
            }
            block[*block_len..64].copy_from_slice(&data[..need]);
            sha256_compress(state, block);
            *block_len = 0;
            data = &data[need..];
        }
        let (chunks, rem): (&[[u8; 64]], &[u8]) = data.as_chunks::<64>();
        for chunk in chunks {
            sha256_compress(state, chunk);
        }
        if !rem.is_empty() {
            block[..rem.len()].copy_from_slice(rem);
            *block_len = rem.len();
        }
    }

    /// Finalizes the SHA-256 digest directly into a 64-byte lowercase ASCII hex array.
    ///
    /// # Returns
    ///
    /// - `[u8; 64]` - 64-byte lowercase hexadecimal digest.
    #[inline]
    pub(crate) fn finalize_hex(self) -> [u8; 64] {
        let Self {
            mut state,
            mut block,
            block_len,
            total_bytes,
        } = self;
        let bit_len: u64 = total_bytes.wrapping_mul(8);
        block[block_len] = 0x80;
        if block_len < 56 {
            block[block_len + 1..56].fill(0);
            block[56..64].copy_from_slice(&bit_len.to_be_bytes());
            sha256_compress(&mut state, &block);
        } else {
            block[block_len + 1..64].fill(0);
            sha256_compress(&mut state, &block);
            let mut last_block: [u8; 64] = [0u8; 64];
            last_block[56..64].copy_from_slice(&bit_len.to_be_bytes());
            sha256_compress(&mut state, &last_block);
        }
        let mut out: [u8; 64] = [0u8; 64];
        let mut pos: usize = 0;
        for word in state {
            for byte in word.to_be_bytes() {
                out[pos] = HEX_LOWER[(byte >> 4) as usize];
                out[pos + 1] = HEX_LOWER[(byte & 0x0f) as usize];
                pos += 2;
            }
        }
        out
    }
}

/// Bounded ring-buffer operations for [`InMemoryAuditSink`].
impl InMemoryAuditSink {
    /// Creates a new [`InMemoryAuditSink`] retaining at most `capacity` records (`>= 1`).
    ///
    /// # Arguments
    ///
    /// - `usize` - Maximum number of records retained in memory.
    ///
    /// # Returns
    ///
    /// - `Self` - Bounded in-memory audit sink.
    pub fn new(capacity: usize) -> Self {
        let cap: usize = capacity.max(1);
        Self {
            capacity: cap,
            records: Mutex::new(VecDeque::with_capacity(cap.min(256))),
        }
    }

    /// Returns a cloned snapshot of all currently buffered records in chronological order.
    ///
    /// # Returns
    ///
    /// - `Vec<AuditRecord>` - Buffered audit records.
    pub fn snapshot(&self) -> Vec<AuditRecord> {
        let Self { records, .. } = self;
        match records.lock() {
            Ok(guard) => guard.iter().cloned().collect(),
            Err(_) => Vec::new(),
        }
    }

    /// Returns the number of currently buffered audit records.
    ///
    /// # Returns
    ///
    /// - `usize` - Current buffer length.
    pub fn len(&self) -> usize {
        let Self { records, .. } = self;
        match records.lock() {
            Ok(guard) => guard.len(),
            Err(_) => 0,
        }
    }

    /// Reports whether zero records are buffered.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when empty.
    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }

    /// Clears all buffered records from memory.
    pub fn clear(&self) {
        let Self { records, .. } = self;
        if let Ok(mut guard) = records.lock() {
            guard.clear();
        }
    }
}

/// Implements [`AuditSink`] for [`InMemoryAuditSink`].
impl AuditSink for InMemoryAuditSink {
    /// Appends `event` to the bounded ring buffer, evicting the oldest record if full.
    ///
    /// # Arguments
    ///
    /// - `AuditRecord` - Finalized audit event.
    fn record(&self, event: AuditRecord) {
        let Self {
            capacity, records, ..
        } = self;
        let evicted: Option<AuditRecord> = if let Ok(mut guard) = records.lock() {
            let old: Option<AuditRecord> = if guard.len() >= *capacity {
                guard.pop_front()
            } else {
                None
            };
            guard.push_back(event);
            old
        } else {
            None
        };
        drop(evicted);
    }
}

/// Default construction for [`AuditConfig`].
impl Default for AuditConfig {
    /// Constructs a default [`AuditConfig`] auditing mutating methods and redacting auth/cookie headers.
    ///
    /// # Returns
    ///
    /// - `Self` - Default configuration.
    fn default() -> Self {
        Self {
            mutations_only: true,
            include_prefixes: Vec::new(),
            exclude_prefixes: Vec::new(),
            capture_headers: Vec::new(),
            redact_headers: vec![AUTHORIZATION.to_owned(), COOKIE.to_owned()],
            request_id_header: DEFAULT_REQUEST_ID_HEADER.to_owned(),
            in_memory_capacity: DEFAULT_AUDIT_CAPACITY,
        }
    }
}

/// Fluent builder helpers for [`AuditConfig`].
impl AuditConfig {
    /// Configures whether only state-mutating HTTP methods are audited (`false` audits all methods).
    ///
    /// # Arguments
    ///
    /// - `bool` - `true` for mutating methods only.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated configuration.
    pub fn with_mutations_only(mut self, enabled: bool) -> Self {
        self.set_mutations_only(enabled);
        self
    }

    /// Restricts auditing to requests matching at least one prefix in `prefixes`.
    ///
    /// # Arguments
    ///
    /// - `I` - Iterator of path prefixes.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated configuration.
    pub fn with_include_prefixes<I, S>(mut self, prefixes: I) -> Self
    where
        I: IntoIterator<Item = S>,
        S: Into<String>,
    {
        self.set_include_prefixes(prefixes.into_iter().map(Into::into).collect());
        self
    }

    /// Excludes matching path prefixes from audit recording.
    ///
    /// # Arguments
    ///
    /// - `I` - Iterator of excluded path prefixes.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated configuration.
    pub fn with_exclude_prefixes<I, S>(mut self, prefixes: I) -> Self
    where
        I: IntoIterator<Item = S>,
        S: Into<String>,
    {
        self.set_exclude_prefixes(prefixes.into_iter().map(Into::into).collect());
        self
    }

    /// Configures request headers copied into each audit record (sensitive headers are auto-redacted).
    ///
    /// # Arguments
    ///
    /// - `I` - Iterator of header names.
    ///
    /// # Returns
    ///
    /// - `Self` - Updated configuration.
    pub fn with_capture_headers<I, S>(mut self, headers: I) -> Self
    where
        I: IntoIterator<Item = S>,
        S: Into<String>,
    {
        self.set_capture_headers(headers.into_iter().map(Into::into).collect());
        self
    }
}

/// Audit filtering, hash-chaining, and recording methods for [`AuditPlugin`].
impl AuditPlugin {
    /// Compiles a standalone [`AuditPlugin`] backed by an [`InMemoryAuditSink`].
    ///
    /// # Arguments
    ///
    /// - `AuditConfig` - Audit configuration.
    ///
    /// # Returns
    ///
    /// - `Self` - Compiled plugin.
    pub fn new(config: AuditConfig) -> Self {
        let mem: Arc<InMemoryAuditSink> =
            Arc::new(InMemoryAuditSink::new(config.get_in_memory_capacity()));
        let sink: Arc<dyn AuditSink> = Arc::clone(&mem) as Arc<dyn AuditSink>;
        Self::build(config, sink, Some(mem))
    }

    /// Compiles a standalone [`AuditPlugin`] writing events to a custom [`AuditSink`].
    ///
    /// # Arguments
    ///
    /// - `AuditConfig` - Audit configuration.
    /// - `Arc<dyn AuditSink>` - Custom sink destination.
    ///
    /// # Returns
    ///
    /// - `Self` - Compiled plugin.
    pub fn with_sink(config: AuditConfig, sink: Arc<dyn AuditSink>) -> Self {
        Self::build(config, sink, None)
    }

    /// Internal constructor compiling normalized prefix and header tables.
    ///
    /// # Arguments
    ///
    /// - `AuditConfig` - Audit configuration.
    /// - `Arc<dyn AuditSink>` - Sink trait object.
    /// - `Option<Arc<InMemoryAuditSink>>` - Optional in-memory ring buffer reference.
    ///
    /// # Returns
    ///
    /// - `Self` - Compiled plugin.
    fn build(
        config: AuditConfig,
        sink: Arc<dyn AuditSink>,
        memory_sink: Option<Arc<InMemoryAuditSink>>,
    ) -> Self {
        let include_prefixes: Box<[String]> = config
            .get_include_prefixes()
            .iter()
            .filter(|p: &&String| !p.trim().is_empty())
            .map(|p: &String| normalize_prefix(p))
            .collect::<Vec<String>>()
            .into_boxed_slice();
        let exclude_prefixes: Box<[String]> = config
            .get_exclude_prefixes()
            .iter()
            .filter(|p: &&String| !p.trim().is_empty())
            .map(|p: &String| normalize_prefix(p))
            .collect::<Vec<String>>()
            .into_boxed_slice();
        let capture_headers_lower: Box<[String]> = config
            .get_capture_headers()
            .iter()
            .map(|h: &String| h.trim().to_ascii_lowercase())
            .filter(|h: &String| !h.is_empty())
            .collect::<Vec<String>>()
            .into_boxed_slice();
        let redact_headers_lower: Box<[String]> = config
            .get_redact_headers()
            .iter()
            .map(|h: &String| h.trim().to_ascii_lowercase())
            .filter(|h: &String| !h.is_empty())
            .collect::<Vec<String>>()
            .into_boxed_slice();
        let request_id_header_lower: String =
            config.get_request_id_header().trim().to_ascii_lowercase();
        Self {
            config,
            include_prefixes,
            exclude_prefixes,
            capture_headers_lower,
            redact_headers_lower,
            request_id_header_lower,
            seq: AtomicU64::new(1),
            last_hash: Mutex::new(AUDIT_GENESIS_BYTES),
            sink,
            memory_sink,
        }
    }

    /// Initializes the global [`AuditPlugin`] singleton with an in-memory ring-buffer sink.
    ///
    /// # Arguments
    ///
    /// - `AuditConfig` - Audit configuration.
    ///
    /// # Returns
    ///
    /// - `&'static Self` - Reference to the global plugin.
    pub fn init(config: AuditConfig) -> &'static Self {
        AUDIT_PLUGIN.get_or_init(|| Self::new(config))
    }

    /// Initializes the global [`AuditPlugin`] singleton with a custom [`AuditSink`].
    ///
    /// # Arguments
    ///
    /// - `AuditConfig` - Audit configuration.
    /// - `Arc<dyn AuditSink>` - Custom audit sink.
    ///
    /// # Returns
    ///
    /// - `&'static Self` - Reference to the global plugin.
    pub fn init_with_sink(config: AuditConfig, sink: Arc<dyn AuditSink>) -> &'static Self {
        AUDIT_PLUGIN.get_or_init(|| Self::with_sink(config, sink))
    }

    /// Returns the initialized global [`AuditPlugin`], if configured.
    ///
    /// # Returns
    ///
    /// - `Option<&'static Self>` - Reference to the global plugin, or `None`.
    #[inline(always)]
    pub fn get() -> Option<&'static Self> {
        AUDIT_PLUGIN.get()
    }

    /// Returns the built-in [`InMemoryAuditSink`] when initialized via [`AuditPlugin::new`] or [`AuditPlugin::init`].
    ///
    /// # Returns
    ///
    /// - `Option<&Arc<InMemoryAuditSink>>` - Reference to the in-memory sink.
    pub fn memory_sink(&self) -> Option<&Arc<InMemoryAuditSink>> {
        let Self { memory_sink, .. } = self;
        memory_sink.as_ref()
    }

    /// Reports whether `request` matches the audit filter policy.
    ///
    /// # Arguments
    ///
    /// - `&Request` - Incoming HTTP request.
    ///
    /// # Returns
    ///
    /// - `bool` - `true` when this request should be audited.
    #[inline]
    pub fn should_audit(&self, request: &Request) -> bool {
        let Self {
            config,
            include_prefixes,
            exclude_prefixes,
            ..
        } = self;
        if config.get_mutations_only() && !is_mutating_method(request.get_method()) {
            return false;
        }
        let path: &str = request.get_path();
        if exclude_prefixes
            .iter()
            .any(|p: &String| path_matches_prefix(path, p))
        {
            return false;
        }
        if !include_prefixes.is_empty()
            && !include_prefixes
                .iter()
                .any(|p: &String| path_matches_prefix(path, p))
        {
            return false;
        }
        true
    }

    /// Builds and hash-chains an [`AuditRecord`] for `ctx` without cloning on dispatch.
    ///
    /// # Arguments
    ///
    /// - `&Context` - Completed request/response context.
    ///
    /// # Returns
    ///
    /// - `AuditRecord` - Finalized hash-chained audit record.
    #[inline]
    fn build_record_for_context(&self, ctx: &Context) -> AuditRecord {
        let Self {
            capture_headers_lower,
            redact_headers_lower,
            request_id_header_lower,
            seq,
            last_hash,
            ..
        } = self;
        let request: &Request = ctx.get_request();
        let latency_us: u64 = ctx
            .try_get_attribute_ref::<Instant, _>(ATTR_AUDIT_START)
            .map(|started: &Instant| started.elapsed().as_micros() as u64)
            .unwrap_or(0);
        let actor_ref: &str = ctx
            .try_get_attribute_ref::<String, _>(ATTR_AUDIT_ACTOR)
            .map(String::as_str)
            .unwrap_or(ANONYMOUS_ACTOR);
        let action_ref: &str = ctx
            .try_get_attribute_ref::<String, _>(ATTR_AUDIT_ACTION)
            .map(String::as_str)
            .unwrap_or_default();
        let request_id_ref: &str = if request_id_header_lower.is_empty() {
            EMPTY_STR
        } else {
            request
                .get_headers()
                .get(request_id_header_lower.as_str())
                .and_then(|vals: &VecDeque<String>| vals.back())
                .map(String::as_str)
                .unwrap_or_default()
        };
        let headers: Vec<(String, String)> = if capture_headers_lower.is_empty() {
            Vec::new()
        } else {
            let mut list: Vec<(String, String)> = Vec::with_capacity(capture_headers_lower.len());
            for name in capture_headers_lower.iter() {
                if let Some(vals) = request.get_headers().get(name.as_str())
                    && let Some(val) = vals.back()
                {
                    let redacted: bool = redact_headers_lower
                        .iter()
                        .any(|r: &String| r.as_str() == name.as_str());
                    let out_val: String = if redacted {
                        REDACTED_VALUE.to_owned()
                    } else {
                        val.clone()
                    };
                    list.push((name.clone(), out_val));
                }
            }
            list
        };
        let method_str: String = request.get_method().to_string();
        let path_ref: &str = request.get_path();
        let status_code: usize = ctx.get_response().get_status_code();
        let sequence: u64 = seq.fetch_add(1, Ordering::Relaxed);
        let timestamp_ms: u64 = current_unix_ms();
        let (prev_bytes, digest_bytes): ([u8; 64], [u8; 64]) =
            if let Ok(mut prev_guard) = last_hash.lock() {
                let prev: [u8; 64] = *prev_guard;
                let digest: [u8; 64] = compute_record_hash_bytes(
                    (sequence, timestamp_ms, status_code),
                    &prev,
                    (&method_str, path_ref),
                    (actor_ref, action_ref, request_id_ref),
                );
                *prev_guard = digest;
                (prev, digest)
            } else {
                let prev: [u8; 64] = AUDIT_GENESIS_BYTES;
                let digest: [u8; 64] = compute_record_hash_bytes(
                    (sequence, timestamp_ms, status_code),
                    &prev,
                    (&method_str, path_ref),
                    (actor_ref, action_ref, request_id_ref),
                );
                (prev, digest)
            };
        let prev_hash: String = from_utf8(&prev_bytes).unwrap_or_default().to_owned();
        let entry_hash: String = from_utf8(&digest_bytes).unwrap_or_default().to_owned();
        AuditRecord {
            sequence,
            timestamp_ms,
            method: method_str,
            path: path_ref.to_owned(),
            status_code,
            latency_us,
            actor: actor_ref.to_owned(),
            action: action_ref.to_owned(),
            request_id: request_id_ref.to_owned(),
            headers,
            prev_hash,
            entry_hash,
        }
    }

    /// Builds, hash-chains, and dispatches an [`AuditRecord`] for `ctx` to the configured sink.
    ///
    /// # Arguments
    ///
    /// - `&Context` - Completed request/response context.
    ///
    /// # Returns
    ///
    /// - `AuditRecord` - The finalized hash-chained audit record.
    pub fn record_context(&self, ctx: &Context) -> AuditRecord {
        let Self { sink, .. } = self;
        let record: AuditRecord = self.build_record_for_context(ctx);
        sink.record(record.clone());
        record
    }

    /// Builds, hash-chains, and moves an [`AuditRecord`] directly to the sink without cloning.
    ///
    /// # Arguments
    ///
    /// - `&Context` - Completed request/response context.
    #[inline]
    pub(crate) fn record_context_hook(&self, ctx: &Context) {
        let Self { sink, .. } = self;
        let record: AuditRecord = self.build_record_for_context(ctx);
        sink.record(record);
    }
}

/// Implements [`ServerHook`] for [`AuditRequestHook`].
impl ServerHook for AuditRequestHook {
    /// Constructs a per-request [`AuditRequestHook`].
    ///
    /// # Arguments
    ///
    /// - `&mut Stream` - Connection stream.
    /// - `&mut Context` - Request context.
    ///
    /// # Returns
    ///
    /// - `Self` - Hook instance.
    #[inline(always)]
    async fn new(_: &mut Stream, _: &mut Context) -> Self {
        Self
    }

    /// Stamps the entry timestamp when the request qualifies for auditing.
    ///
    /// # Arguments
    ///
    /// - `Self` - Hook instance.
    /// - `&mut Stream` - Connection stream.
    /// - `&mut Context` - Request context.
    ///
    /// # Returns
    ///
    /// - `Status` - Always `Status::Continue`.
    #[inline(always)]
    async fn handle(self, _: &mut Stream, ctx: &mut Context) -> Status {
        let Some(plugin) = AuditPlugin::get() else {
            return Status::Continue;
        };
        if plugin.should_audit(ctx.get_request()) {
            ctx.set_attribute(ATTR_AUDIT_START, Instant::now());
        }
        Status::Continue
    }
}

/// Implements [`ServerHook`] for [`AuditResponseHook`].
impl ServerHook for AuditResponseHook {
    /// Constructs a per-response [`AuditResponseHook`].
    ///
    /// # Arguments
    ///
    /// - `&mut Stream` - Connection stream.
    /// - `&mut Context` - Request context.
    ///
    /// # Returns
    ///
    /// - `Self` - Hook instance.
    #[inline(always)]
    async fn new(_: &mut Stream, _: &mut Context) -> Self {
        Self
    }

    /// Emits a finalized hash-chained [`AuditRecord`] for audited requests.
    ///
    /// # Arguments
    ///
    /// - `Self` - Hook instance.
    /// - `&mut Stream` - Connection stream.
    /// - `&mut Context` - Request context.
    ///
    /// # Returns
    ///
    /// - `Status` - Always `Status::Continue`.
    #[inline(always)]
    async fn handle(self, _: &mut Stream, ctx: &mut Context) -> Status {
        let Some(plugin) = AuditPlugin::get() else {
            return Status::Continue;
        };
        if plugin.should_audit(ctx.get_request()) {
            plugin.record_context_hook(ctx);
        }
        Status::Continue
    }
}