3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Cap delay strings to 100 years

This is to avoid issues with max date values and other similar edge
cases. This was an issue when accidentally passing a user ID as the
time value for e.g. reminders.
This commit is contained in:
Dragory 2020-10-13 19:45:37 +03:00
parent eee1c6d789
commit dbcd5e7de2
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -296,6 +296,10 @@ export const tDelayString = new t.Type<string, string>(
s => s,
);
// To avoid running into issues with the JS max date vaLue, we cap maximum delay strings *far* below that.
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#The_ECMAScript_epoch_and_timestamps
const MAX_DELAY_STRING_AMOUNT = 100 * 365 * DAYS;
/**
* Turns a "delay string" such as "1h30m" to milliseconds
*/
@ -317,6 +321,10 @@ export function convertDelayStringToMS(str, defaultUnit = "m"): number {
return null;
}
if (ms > MAX_DELAY_STRING_AMOUNT) {
return null;
}
return ms;
}