@@ -143,8 +143,31 @@ impl DdkRpc for DdkNode {
143143 contract_input,
144144 counter_party,
145145 } = request. into_inner ( ) ;
146+
147+ if contract_input. len ( ) > 1_000_000 {
148+ return Err ( Status :: new (
149+ Code :: InvalidArgument ,
150+ "Contract input too large (max: 1MB)" ,
151+ ) ) ;
152+ }
153+
146154 let contract_input: ContractInput =
147- serde_json:: from_slice ( & contract_input) . expect ( "couldn't get bytes correct" ) ;
155+ serde_json:: from_slice ( & contract_input) . map_err ( |e| {
156+ Status :: new (
157+ Code :: InvalidArgument ,
158+ format ! ( "Invalid contract input: {}" , e) ,
159+ )
160+ } ) ?;
161+
162+ if contract_input. fee_rate > 1000 {
163+ return Err ( Status :: new (
164+ Code :: InvalidArgument ,
165+ format ! (
166+ "Fee rate too high: {} sat/vbyte (max: 1000)" ,
167+ contract_input. fee_rate
168+ ) ,
169+ ) ) ;
170+ }
148171 let mut oracle_announcements = Vec :: new ( ) ;
149172 for info in & contract_input. contract_infos {
150173 let announcement = self
@@ -297,7 +320,16 @@ impl DdkRpc for DdkNode {
297320 request : Request < ConnectRequest > ,
298321 ) -> Result < Response < ConnectResponse > , Status > {
299322 let ConnectRequest { pubkey, host } = request. into_inner ( ) ;
300- let pubkey = PublicKey :: from_str ( & pubkey) . unwrap ( ) ;
323+
324+ if host. len ( ) > 255 {
325+ return Err ( Status :: new (
326+ Code :: InvalidArgument ,
327+ "Host string too long (max: 255 characters)" ,
328+ ) ) ;
329+ }
330+
331+ let pubkey = PublicKey :: from_str ( & pubkey)
332+ . map_err ( |e| Status :: new ( Code :: InvalidArgument , format ! ( "Invalid pubkey: {}" , e) ) ) ?;
301333 self . node . transport . connect_outbound ( pubkey, & host) . await ;
302334 Ok ( Response :: new ( ConnectResponse { } ) )
303335 }
@@ -336,7 +368,17 @@ impl DdkRpc for DdkNode {
336368 amount,
337369 fee_rate,
338370 } = request. into_inner ( ) ;
339- let address = Address :: from_str ( & address) . unwrap ( ) . assume_checked ( ) ;
371+
372+ if fee_rate > 1000 {
373+ return Err ( Status :: new (
374+ Code :: InvalidArgument ,
375+ format ! ( "Fee rate too high: {} sat/vbyte (max: 1000)" , fee_rate) ,
376+ ) ) ;
377+ }
378+
379+ let address = Address :: from_str ( & address)
380+ . map_err ( |e| Status :: new ( Code :: InvalidArgument , format ! ( "Invalid address: {}" , e) ) ) ?
381+ . assume_checked ( ) ;
340382 let amount = Amount :: from_sat ( amount) ;
341383 let fee_rate = match FeeRate :: from_sat_per_vb ( fee_rate) {
342384 Some ( f) => f,
0 commit comments