File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,10 +39,17 @@ export function encodeMcpHeaderValue(value: string): string {
3939export function decodeMcpHeaderValue ( value : string ) : string {
4040 const m = / ^ = \? b a s e 6 4 \? ( .+ ) \? = $ / . exec ( value ) ;
4141 if ( ! m ) return value ;
42- // atob output is one Latin-1 char per byte; charCodeAt gives the byte value back.
43- // eslint-disable-next-line unicorn/prefer-code-point
44- const bytes = Uint8Array . from ( atob ( m [ 1 ] ! ) , c => c . charCodeAt ( 0 ) ) ;
45- return new TextDecoder ( ) . decode ( bytes ) ;
42+ try {
43+ // atob output is one Latin-1 char per byte; charCodeAt gives the byte value back.
44+ // eslint-disable-next-line unicorn/prefer-code-point
45+ const bytes = Uint8Array . from ( atob ( m [ 1 ] ! ) , c => c . charCodeAt ( 0 ) ) ;
46+ return new TextDecoder ( ) . decode ( bytes ) ;
47+ } catch {
48+ // Malformed base64 from a misbehaving client. Return the raw value so
49+ // validateMcpHeaders falls through to the 400/-32001 mismatch path
50+ // instead of bubbling a DOMException up to the transport's outer catch.
51+ return value ;
52+ }
4653}
4754
4855/**
You can’t perform that action at this time.
0 commit comments