@@ -1260,10 +1260,23 @@ export class RuntimeBrokerCapabilityRouter implements ElizaCapabilityRouter {
12601260 } ) ;
12611261 const object = requireObject ( result , "plugin.asset.get" ) ;
12621262 const integrity = optionalString ( object , "integrity" , "plugin.asset.get" ) ;
1263+ const path = requireNonEmptyString ( object , "path" , "plugin.asset.get" ) ;
1264+ validateRemotePluginAssetPath ( path , "path" , "plugin.asset.get" ) ;
1265+ const contentType = requireNonEmptyString (
1266+ object ,
1267+ "contentType" ,
1268+ "plugin.asset.get" ,
1269+ ) ;
1270+ validateHeaderSafeString ( contentType , "contentType" , "plugin.asset.get" ) ;
1271+ const bodyBase64 = requireString ( object , "bodyBase64" , "plugin.asset.get" ) ;
1272+ validateBase64String ( bodyBase64 , "bodyBase64" , "plugin.asset.get" ) ;
1273+ if ( integrity !== undefined ) {
1274+ validateHeaderSafeString ( integrity , "integrity" , "plugin.asset.get" ) ;
1275+ }
12631276 return {
1264- path : requireString ( object , "path" , "plugin.asset.get" ) ,
1265- contentType : requireString ( object , "contentType" , "plugin.asset.get" ) ,
1266- bodyBase64 : requireString ( object , "bodyBase64" , "plugin.asset.get" ) ,
1277+ path,
1278+ contentType,
1279+ bodyBase64,
12671280 ...( integrity === undefined ? { } : { integrity } ) ,
12681281 } ;
12691282 }
@@ -2802,6 +2815,31 @@ function validateRemotePluginAssetPath(
28022815 }
28032816}
28042817
2818+ function validateHeaderSafeString (
2819+ value : string ,
2820+ key : string ,
2821+ method : string ,
2822+ ) : void {
2823+ if ( / [ \r \n \0 ] / . test ( value ) ) {
2824+ throw decodeError ( method , `${ key } must not contain control characters.` ) ;
2825+ }
2826+ }
2827+
2828+ function validateBase64String (
2829+ value : string ,
2830+ key : string ,
2831+ method : string ,
2832+ ) : void {
2833+ if (
2834+ value . length > 0 &&
2835+ ! / ^ (?: [ A - Z a - z 0 - 9 + / ] { 4 } ) * (?: [ A - Z a - z 0 - 9 + / ] { 2 } = = | [ A - Z a - z 0 - 9 + / ] { 3 } = ) ? $ / . test (
2836+ value ,
2837+ )
2838+ ) {
2839+ throw decodeError ( method , `${ key } must be valid base64.` ) ;
2840+ }
2841+ }
2842+
28052843function requirePluginActionResult (
28062844 value : JsonValue | undefined ,
28072845 method : string ,
0 commit comments