Skip to content

Commit 199e1a1

Browse files
authored
Merge pull request #564 from codex-team/feat/rate-limits-settings
validation
2 parents 01b2c7f + 11416d7 commit 199e1a1

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hawk.api",
3-
"version": "1.2.7",
3+
"version": "1.2.8",
44
"main": "index.ts",
55
"license": "BUSL-1.1",
66
"scripts": {

src/resolvers/project.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)