@@ -198,6 +198,48 @@ module.exports = {
198198 throw new ApolloError ( 'Unable to update demo project' ) ;
199199 }
200200
201+ // Validate rate limit settings if provided
202+ if ( rateLimitSettings !== null && rateLimitSettings !== undefined ) {
203+ const { N, T } = rateLimitSettings ;
204+
205+ // Validate that N and T exist
206+ if ( N === undefined || N === null || T === undefined || T === null ) {
207+ throw new UserInputError (
208+ 'Rate limit settings must contain both N (threshold) and T (period) fields.'
209+ ) ;
210+ }
211+
212+ // Validate N (threshold) - must be positive integer > 0
213+ if ( typeof N !== 'number' || ! Number . isInteger ( N ) || N <= 0 ) {
214+ throw new UserInputError (
215+ 'Invalid rate limit threshold. Must be a positive integer greater than 0.'
216+ ) ;
217+ }
218+
219+ // Validate T (period) - must be positive integer >= 60
220+ if ( typeof T !== 'number' || ! Number . isInteger ( T ) || T < 60 ) {
221+ throw new UserInputError (
222+ 'Invalid rate limit period. Must be a positive integer greater than or equal to 60 seconds.'
223+ ) ;
224+ }
225+
226+ // Validate reasonable maximums (prevent extremely large values)
227+ const MAX_THRESHOLD = 1000000000 ; // 1 billion
228+ const MAX_PERIOD = 31536000 ; // 1 year in seconds
229+
230+ if ( N > MAX_THRESHOLD ) {
231+ throw new UserInputError (
232+ `Rate limit threshold cannot exceed ${ MAX_THRESHOLD . toLocaleString ( ) } .`
233+ ) ;
234+ }
235+
236+ if ( T > MAX_PERIOD ) {
237+ throw new UserInputError (
238+ `Rate limit period cannot exceed ${ MAX_PERIOD . toLocaleString ( ) } seconds (1 year).`
239+ ) ;
240+ }
241+ }
242+
201243 try {
202244 return project . updateProject ( {
203245 rateLimitSettings : rateLimitSettings || null ,
0 commit comments