@@ -12,6 +12,7 @@ import {
1212} from "openclaw/plugin-sdk/number-runtime" ;
1313import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime" ;
1414import { isPrivateNetworkOptInEnabled } from "openclaw/plugin-sdk/ssrf-runtime" ;
15+ import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime" ;
1516import type { ResolvedMattermostAccount } from "../mattermost/accounts.js" ;
1617import { getMattermostRuntime } from "../runtime.js" ;
1718import {
@@ -142,35 +143,37 @@ function isDeletedMattermostCommand(command: { delete_at?: number }): boolean {
142143
143144function sanitizeCommandLookupError ( error : unknown ) : string {
144145 const raw = error instanceof Error ? error . message : String ( error ) ;
145- return raw
146- . replace ( / [ \r \n \t ] / gu, " " )
147- . replace ( / h t t p s ? : \/ \/ [ ^ \s ) \] } ] + / giu, ( urlText ) => {
148- try {
149- const url = new URL ( urlText ) ;
150- if ( url . username || url . password ) {
151- url . username = "redacted" ;
152- url . password = "redacted" ;
153- }
154- for ( const key of url . searchParams . keys ( ) ) {
155- if ( SECRET_LOG_KEYS . has ( key . toLowerCase ( ) ) ) {
156- url . searchParams . set ( key , "redacted" ) ;
146+ return truncateUtf16Safe (
147+ raw
148+ . replace ( / [ \r \n \t ] / gu, " " )
149+ . replace ( / h t t p s ? : \/ \/ [ ^ \s ) \] } ] + / giu, ( urlText ) => {
150+ try {
151+ const url = new URL ( urlText ) ;
152+ if ( url . username || url . password ) {
153+ url . username = "redacted" ;
154+ url . password = "redacted" ;
157155 }
156+ for ( const key of url . searchParams . keys ( ) ) {
157+ if ( SECRET_LOG_KEYS . has ( key . toLowerCase ( ) ) ) {
158+ url . searchParams . set ( key , "redacted" ) ;
159+ }
160+ }
161+ return url . toString ( ) ;
162+ } catch {
163+ return urlText ;
158164 }
159- return url . toString ( ) ;
160- } catch {
161- return urlText ;
162- }
163- } )
164- . replace ( / ( ^ | [ ^ \w - ] ) ( B e a r e r | T o k e n ) \s + [ A - Z a - z 0 - 9 . _ ~ + / = - ] + / giu, "$1$2 [redacted]" )
165- . replace (
166- / \b ( t o k e n | a u t h o r i z a t i o n | a c c e s s _ t o k e n | r e f r e s h _ t o k e n | c l i e n t _ s e c r e t | b o t T o k e n ) \b ( \s * [ " ' ] ? \s * (?: = | : ) \s * [ " ' ] ? ) [ ^ " ' , \s ; } ] + / giu,
167- "$1$2[redacted]" ,
168- )
169- . slice ( 0 , 300 ) ;
165+ } )
166+ . replace ( / ( ^ | [ ^ \w - ] ) ( B e a r e r | T o k e n ) \s + [ A - Z a - z 0 - 9 . _ ~ + / = - ] + / giu, "$1$2 [redacted]" )
167+ . replace (
168+ / \b ( t o k e n | a u t h o r i z a t i o n | a c c e s s _ t o k e n | r e f r e s h _ t o k e n | c l i e n t _ s e c r e t | b o t T o k e n ) \b ( \s * [ " ' ] ? \s * (?: = | : ) \s * [ " ' ] ? ) [ ^ " ' , \s ; } ] + / giu,
169+ "$1$2[redacted]" ,
170+ ) ,
171+ 300 ,
172+ ) ;
170173}
171174
172175function sanitizeMattermostLogValue ( value : string ) : string {
173- return value . replace ( / [ \r \n \t ] / gu, " " ) . slice ( 0 , 200 ) ;
176+ return truncateUtf16Safe ( value . replace ( / [ \r \n \t ] / gu, " " ) , 200 ) ;
174177}
175178
176179async function withCommandLookupTimeout < T > ( task : ( signal : AbortSignal ) => Promise < T > ) : Promise < T > {
0 commit comments