Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix: reject invalid calendar dates in task fields

MonsProprea1e42481476e
diff --git a/apps/api/src/task/validate-task-fields.ts b/apps/api/src/task/validate-task-fields.ts
index 66f1fe899..236210f9e 100644
--- a/apps/api/src/task/validate-task-fields.ts
+++ b/apps/api/src/task/validate-task-fields.ts
@@ -23,18 +23,35 @@ export function validateCustomFieldValue(
}
if (type === "date") {
- const timestamp = Date.parse(value);
- if (Number.isNaN(timestamp)) {
- return `Custom field "${fieldName}" expects a valid ISO 8601 date, got "${value}".`;
- }
-
const isoMatch =
- /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d{3})?(Z|[+-]\d{2}:\d{2})?)?$/.test(
+ /^(\d{4})-(\d{2})-(\d{2})(T\d{2}:\d{2}:\d{2}(\.\d{3})?(Z|[+-]\d{2}:\d{2})?)?$/.exec(
value,
);
+
if (!isoMatch) {
return `Custom field "${fieldName}" expects a date in YYYY-MM-DD or ISO 8601 format, got "${value}".`;
}
+
+ const timestamp = Date.parse(value);
+ if (Number.isNaN(timestamp)) {
+ return `Custom field "${fieldName}" expects a valid ISO 8601 date, got "${value}".`;
+ }
+
+ const year = Number(isoMatch[1]);
+ const month = Number(isoMatch[2]);
+ const day = Number(isoMatch[3]);
+
+ const calendarDate = new Date(0);
+ calendarDate.setUTCFullYear(year, month - 1, day);
+ calendarDate.setUTCHours(0, 0, 0, 0);
+
+ if (
+ calendarDate.getUTCFullYear() !== year ||
+ calendarDate.getUTCMonth() !== month - 1 ||
+ calendarDate.getUTCDate() !== day
+ ) {
+ return `Custom field "${fieldName}" expects a valid ISO 8601 date, got "${value}".`;
+ }
}
if (type === "dropdown") {