Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

fix(api): validate every date that reaches a date column (#307)

Croffe4ad867c9b61
diff --git a/AGENTS.md b/AGENTS.md
index 27e9a1b7..5315d642 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -21,8 +21,10 @@ solutions.
Write a minimum of comments. A comment explains why, the code explains what — cover a comment
with your hand and read the code under it: if the fact is recoverable from the code alone, the
-comment does not belong there. A wrong comment is worse than no comment, so change a comment in
-the same edit as the code it describes, or delete it. Layout and styling are never commented:
+comment does not belong there. A comment longer than the code under it is too long. A wrong
+comment is worse than no comment, so change a comment in the same edit as the code it describes,
+or delete it. The comment density of the code around a change is not a pattern to follow: this
+rule wins over matching the neighbours. Layout and styling are never commented:
no notes on positioning, sticky or overflow behaviour, spacing, or why a class is set. The full
rules, and the pass that removes comments that no longer hold, are in the `tidy` skill.
diff --git a/apps/api/src/modules/custom-fields/__tests__/integration/custom-fields.test.ts b/apps/api/src/modules/custom-fields/__tests__/integration/custom-fields.test.ts
index 41b82429..ef4f52a8 100644
--- a/apps/api/src/modules/custom-fields/__tests__/integration/custom-fields.test.ts
+++ b/apps/api/src/modules/custom-fields/__tests__/integration/custom-fields.test.ts
@@ -287,6 +287,22 @@ describe('custom-fields', () => {
});
});
+ it('rejects a value a date field cannot hold', async () => {
+ const { asOwner, issueId } = await setupWithIssue();
+ const field = (await fields(asOwner).post({ name: 'Ship on', fieldType: 'date' })).data!;
+
+ for (const value of ['01.02.2026', '2026-13-45', '2026-02-30']) {
+ const res = await asOwner.issues({ issueId }).fields({ fieldId: field.id }).put({ value });
+ expect(res.status).toBe(400);
+ }
+
+ const ok = await asOwner
+ .issues({ issueId })
+ .fields({ fieldId: field.id })
+ .put({ value: '2026-02-01' });
+ expect(ok.status).toBe(200);
+ });
+
it('changes the type and clears the values issues held under the old one', async () => {
const { asOwner, issueId } = await setupWithIssue();
const field = (await fields(asOwner).post({ name: 'Severity', fieldType: 'text' })).data!;
diff --git a/apps/api/src/modules/issues/__tests__/integration/issues.test.ts b/apps/api/src/modules/issues/__tests__/integration/issues.test.ts
index 86c6b1ec..53ea7bee 100644
--- a/apps/api/src/modules/issues/__tests__/integration/issues.test.ts
+++ b/apps/api/src/modules/issues/__tests__/integration/issues.test.ts
@@ -281,6 +281,25 @@ describe('issues', () => {
});
expect(res.status).toBe(400);
});
+
+ it('rejects a due date an update sends in another notation', async () => {
+ const { asOwner, columnId } = await setupProject();
+ const created = await asOwner
+ .projects({ projectKey: 'MKT' })
+ .issues.post({ columnId, title: 'Dated' });
+ const res = await asOwner
+ .issues({ issueId: created.data!.id })
+ .patch({ dueDate: '01.02.2026' });
+ expect(res.status).toBe(400);
+ });
+
+ it('rejects a date whose month does not exist', async () => {
+ const { asOwner, columnId } = await setupProject();
+ const res = await asOwner
+ .projects({ projectKey: 'MKT' })
+ .issues.post({ columnId, title: 'Dated', dueDate: '2026-13-45' });
+ expect(res.status).toBe(400);
+ });
});
describe('update', () => {
diff --git a/apps/api/src/modules/issues/model.ts b/apps/api/src/modules/issues/model.ts
index d25e3b27..0c6c69e4 100644
--- a/apps/api/src/modules/issues/model.ts
+++ b/apps/api/src/modules/issues/model.ts
@@ -563,8 +563,8 @@ export const updateIssueBody = t.Object({
),
estimatePoints: t.Optional(EstimatePointsSchema),
estimateMinutes: t.Optional(EstimateMinutesSchema),
- startDate: t.Optional(t.Nullable(t.String({ description: "Start date 'YYYY-MM-DD', or null." }))),
- dueDate: t.Optional(t.Nullable(t.String({ description: "Due date 'YYYY-MM-DD', or null." }))),
+ startDate: t.Optional(t.Nullable(isoDate("Start date 'YYYY-MM-DD', or null."))),
+ dueDate: t.Optional(t.Nullable(isoDate("Due date 'YYYY-MM-DD', or null."))),
labelIds: t.Optional(
t.Array(t.Integer(), { description: "Replace the issue's labels with these ids." }),
),
diff --git a/apps/api/src/modules/issues/service.ts b/apps/api/src/modules/issues/service.ts
index 80f699e0..58e7e5c6 100644
--- a/apps/api/src/modules/issues/service.ts
+++ b/apps/api/src/modules/issues/service.ts
@@ -1411,6 +1411,16 @@ function isHttpUrl(value: string): boolean {
return url.protocol === 'http:' || url.protocol === 'https:';
}
+// Checked here, not in the schema: one `value` carries every field type.
+function parseDate(value: unknown): string | null {
+ if (value == null || value === '') return null;
+ if (typeof value === 'string') {
+ const day = new Date(`${value}T00:00:00Z`);
+ if (!Number.isNaN(day.getTime()) && day.toISOString().slice(0, 10) === value) return value;
+ }
+ throw new HttpError(400, "Date must be a calendar day, 'YYYY-MM-DD'");
+}
+
// A datetime value on the way in: an ISO datetime string, or null when unset.
// Anything else (a number, a date-only string, unparseable text) is rejected: a
// value without a time of day would land on midnight UTC, which is another day
@@ -1587,7 +1597,7 @@ export async function setIssueFieldValue(
column = { valueBool: input.value == null ? null : Boolean(input.value) };
break;
case 'date':
- column = { valueDate: (input.value as string) ?? null };
+ column = { valueDate: parseDate(input.value) };
break;
case 'member':
column = { valueUserId: memberUserId };
diff --git a/apps/api/src/shared/schemas.ts b/apps/api/src/shared/schemas.ts
index 612175ce..dc4f5d4f 100644
--- a/apps/api/src/shared/schemas.ts
+++ b/apps/api/src/shared/schemas.ts
@@ -1,8 +1,5 @@
import { t } from 'elysia';
-// Request schemas shared by more than one feature.
-
-// A calendar day, as the `date` columns hold it. The caller passes what the date
-// stands for on its route, which is what the OpenAPI docs and the MCP tools show.
+// A calendar day, as the `date` columns hold it.
export const isoDate = (description: string) =>
- t.String({ pattern: '^\\d{4}-\\d{2}-\\d{2}$', description });
+ t.String({ pattern: '^\\d{4}-\\d{2}-\\d{2}$', format: 'date', description });