11// Discord plugin module implements rest routes behavior.
2+ import { redactIdentifier } from "openclaw/plugin-sdk/logging-core" ;
23import {
34 asDateTimestampMs ,
45 resolveExpiresAtMsFromDurationMs ,
@@ -7,9 +8,25 @@ import {
78type QueryValue = string | number | boolean ;
89
910const RATE_LIMIT_HEADER_NUMBER_RE = / ^ \d + (?: \. \d + ) ? $ / ;
11+ const DISCORD_ROUTE_IDENTIFIER_HASH_LENGTH = 32 ;
12+
13+ function redactWebhookTokenInPath ( path : string ) : string {
14+ const hasLeadingSlash = path . startsWith ( "/" ) ;
15+ const segments = path . replace ( / ^ \/ + / , "" ) . split ( "/" ) ;
16+ if ( segments [ 0 ] !== "webhooks" || ! segments [ 1 ] || ! segments [ 2 ] ) {
17+ return path ;
18+ }
19+ // Webhook tokens are route identity, but they are also credentials. Keep
20+ // stable grouping without retaining the raw token in scheduler diagnostics.
21+ segments [ 2 ] = redactIdentifier ( segments [ 2 ] , {
22+ len : DISCORD_ROUTE_IDENTIFIER_HASH_LENGTH ,
23+ } ) ;
24+ return `${ hasLeadingSlash ? "/" : "" } ${ segments . join ( "/" ) } ` ;
25+ }
1026
1127export function createRouteKey ( method : string , path : string ) : string {
12- return `${ method . toUpperCase ( ) } ${ path . split ( "?" ) [ 0 ] ?? path } ` ;
28+ const pathname = path . split ( "?" ) [ 0 ] ?? path ;
29+ return `${ method . toUpperCase ( ) } ${ redactWebhookTokenInPath ( pathname ) } ` ;
1330}
1431
1532function readTopLevelRouteKey ( path : string ) : string {
@@ -19,7 +36,11 @@ function readTopLevelRouteKey(path: string): string {
1936 return pathname ;
2037 }
2138 if ( first === "channels" || first === "guilds" || first === "webhooks" ) {
22- return first === "webhooks" && token ? `${ first } /${ id } /${ token } ` : `${ first } /${ id } ` ;
39+ return first === "webhooks" && token
40+ ? `${ first } /${ id } /${ redactIdentifier ( token , {
41+ len : DISCORD_ROUTE_IDENTIFIER_HASH_LENGTH ,
42+ } ) } `
43+ : `${ first } /${ id } ` ;
2344 }
2445 return first ;
2546}
0 commit comments