@@ -328,20 +328,12 @@ pub struct LSPS5WebhookUrl(LSPSUrl);
328
328
impl LSPS5WebhookUrl {
329
329
/// Create a new LSPS5 webhook URL.
330
330
pub fn new ( url : UntrustedString ) -> Result < Self , LSPS5Error > {
331
- let parsed_url = LSPSUrl :: parse ( url. 0 . clone ( ) )
332
- . map_err ( |_e| LSPS5ProtocolError :: UrlParse ( "Error parsing URL" . to_string ( ) ) ) ?;
333
- if parsed_url. url_length ( ) > MAX_WEBHOOK_URL_LENGTH {
331
+ let raw_url = url. to_string ( ) ;
332
+ if raw_url. len ( ) > MAX_WEBHOOK_URL_LENGTH {
334
333
return Err ( LSPS5ProtocolError :: WebhookUrlTooLong . into ( ) ) ;
335
334
}
336
- if !parsed_url. is_https ( ) {
337
- return Err ( LSPS5ProtocolError :: UnsupportedProtocol . into ( ) ) ;
338
- }
339
- if !parsed_url. is_public ( ) {
340
- return Err ( LSPS5ProtocolError :: UrlParse (
341
- "Webhook URL must be a public URL" . to_string ( ) ,
342
- )
343
- . into ( ) ) ;
344
- }
335
+ let parsed_url = LSPSUrl :: parse ( url. 0 ) ?;
336
+
345
337
Ok ( Self ( parsed_url) )
346
338
}
347
339
@@ -807,13 +799,14 @@ mod tests {
807
799
#[ test]
808
800
fn test_url_security_validation ( ) {
809
801
let urls_that_should_throw = [
810
- "https://10.0.0.1/webhook" ,
811
- "https://192.168.1.1/webhook" ,
812
- "https://172.16.0.1/webhook" ,
813
- "https://172.31.255.255/webhook" ,
814
- "https://localhost/webhook" ,
815
802
"test-app" ,
816
803
"http://example.com/webhook" ,
804
+ "ftp://example.com/webhook" ,
805
+ "ws://example.com/webhook" ,
806
+ "ws+unix://example.com/webhook" ,
807
+ "ws+unix:/example.com/webhook" ,
808
+ "ws+unix://example.com/webhook?param=value" ,
809
+ "ws+unix:/example.com/webhook?param=value" ,
817
810
] ;
818
811
819
812
for url_str in urls_that_should_throw. iter ( ) {
0 commit comments