@@ -102,7 +102,7 @@ function validateNotificationsRuleTresholdAndPeriod(
102102/**
103103 * Return true if all passed channels are filled with correct endpoints
104104 */
105- function validateNotificationsRuleChannels ( channels : NotificationsChannelsDBScheme ) : string | null {
105+ async function validateNotificationsRuleChannels ( channels : NotificationsChannelsDBScheme ) : Promise < string | null > {
106106 if ( channels . email ! . isEnabled ) {
107107 if ( ! / ^ [ a - z A - Z 0 - 9 . _ % + - ] + @ [ a - z A - Z 0 - 9 . - ] + \. [ a - z A - Z ] { 2 , } $ / . test ( channels . email ! . endpoint ) ) {
108108 return 'Invalid email endpoint passed' ;
@@ -127,17 +127,12 @@ function validateNotificationsRuleChannels(channels: NotificationsChannelsDBSche
127127 }
128128 }
129129
130- return null ;
131- }
132-
133- /**
134- * Validates webhook endpoint for SSRF safety (async DNS check)
135- *
136- * @param channels - notification channels to validate
137- */
138- async function validateWebhookChannel ( channels : NotificationsChannelsDBScheme ) : Promise < string | null > {
139130 if ( channels . webhook ?. isEnabled && channels . webhook . endpoint ) {
140- return validateWebhookEndpoint ( channels . webhook . endpoint ) ;
131+ const webhookError = await validateWebhookEndpoint ( channels . webhook . endpoint ) ;
132+
133+ if ( webhookError !== null ) {
134+ return webhookError ;
135+ }
141136 }
142137
143138 return null ;
@@ -166,18 +161,12 @@ export default {
166161 throw new ApolloError ( 'No project with such id' ) ;
167162 }
168163
169- const channelsValidationResult = validateNotificationsRuleChannels ( input . channels ) ;
164+ const channelsValidationResult = await validateNotificationsRuleChannels ( input . channels ) ;
170165
171166 if ( channelsValidationResult !== null ) {
172167 throw new UserInputError ( channelsValidationResult ) ;
173168 }
174169
175- const webhookValidationResult = await validateWebhookChannel ( input . channels ) ;
176-
177- if ( webhookValidationResult !== null ) {
178- throw new UserInputError ( webhookValidationResult ) ;
179- }
180-
181170 if ( input . whatToReceive === ReceiveTypes . SEEN_MORE ) {
182171 const thresholdValidationResult = validateNotificationsRuleTresholdAndPeriod ( input . threshold , input . thresholdPeriod ) ;
183172
@@ -210,18 +199,12 @@ export default {
210199 throw new ApolloError ( 'No project with such id' ) ;
211200 }
212201
213- const channelsValidationResult = validateNotificationsRuleChannels ( input . channels ) ;
202+ const channelsValidationResult = await validateNotificationsRuleChannels ( input . channels ) ;
214203
215204 if ( channelsValidationResult !== null ) {
216205 throw new UserInputError ( channelsValidationResult ) ;
217206 }
218207
219- const webhookValidationResult = await validateWebhookChannel ( input . channels ) ;
220-
221- if ( webhookValidationResult !== null ) {
222- throw new UserInputError ( webhookValidationResult ) ;
223- }
224-
225208 if ( input . whatToReceive === ReceiveTypes . SEEN_MORE ) {
226209 const thresholdValidationResult = validateNotificationsRuleTresholdAndPeriod ( input . threshold , input . thresholdPeriod ) ;
227210
0 commit comments