@@ -693,25 +693,30 @@ export class BackendClient {
693693 * ```
694694 */
695695 private buildWorkflowUrl ( input : string ) : string {
696- if ( ! input ?. trim ( ) ) {
696+ const sanitizedInput = input
697+ . trim ( )
698+ . replace ( / [ ^ \w - . / : ] / g, "" )
699+ . toLowerCase ( ) ;
700+ if ( ! sanitizedInput ) {
697701 throw new Error ( "URL or endpoint ID is required" ) ;
698702 }
699703
700- input = input . trim ( ) . toLowerCase ( ) ;
701704 let url : string ;
702-
703- const isUrl = input . includes ( "." ) || input . startsWith ( "http" ) ;
705+ const isUrl = sanitizedInput . includes ( "." ) || sanitizedInput . startsWith ( "http" ) ;
704706
705707 if ( isUrl ) {
706708 // Try to parse the input as a URL
707709 let parsedUrl : URL ;
708710 try {
709- const urlString = input . startsWith ( "http" )
710- ? input
711- : `https://${ input } ` ;
711+ const urlString = sanitizedInput . startsWith ( "http" )
712+ ? sanitizedInput
713+ : `https://${ sanitizedInput } ` ;
712714 parsedUrl = new URL ( urlString ) ;
713715 } catch ( error ) {
714- throw new Error ( `The provided URL is malformed: "${ input } ". Please provide a valid URL.` ) ;
716+ throw new Error ( `
717+ The provided URL is malformed: "${ sanitizedInput } ".
718+ Please provide a valid URL.
719+ ` ) ;
715720 }
716721
717722 // Validate the hostname to prevent potential DNS rebinding attacks
@@ -722,14 +727,14 @@ export class BackendClient {
722727 url = parsedUrl . href ;
723728 } else {
724729 // If the input is an ID, construct the full URL using the base domain
725- if ( ! / ^ e ( n | o ) [ a - z 0 - 9 - ] + $ / i. test ( input ) ) {
730+ if ( ! / ^ e ( n | o ) [ a - z 0 - 9 - ] + $ / i. test ( sanitizedInput ) ) {
726731 throw new Error ( `
727732 Invalid endpoint ID format.
728733 Must contain only letters, numbers, and hyphens, and start with either "en" or "eo".
729734 ` ) ;
730735 }
731736
732- url = `https://${ input } .${ this . workflowDomain } ` ;
737+ url = `https://${ sanitizedInput } .${ this . workflowDomain } ` ;
733738 }
734739
735740 return url ;
0 commit comments