fix: too strict cron expression validation (#29138)

This commit is contained in:
Daniel Dietzler 2026-06-16 15:20:40 +02:00 committed by GitHub
parent a23a7c69ae
commit e70a1163f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 7 deletions

View file

@ -18490,7 +18490,6 @@
"properties": {
"cronExpression": {
"description": "Cron expression",
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
"type": "string"
},
"enabled": {
@ -25677,7 +25676,6 @@
"properties": {
"cronExpression": {
"description": "Cron expression for when the integrity check should run",
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
"type": "string"
},
"enabled": {
@ -25710,7 +25708,6 @@
"properties": {
"cronExpression": {
"description": "Cron expression for when the integrity check should run",
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
"type": "string"
},
"enabled": {
@ -25810,7 +25807,6 @@
"properties": {
"cronExpression": {
"description": "Cron expression",
"pattern": "(((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7}",
"type": "string"
},
"enabled": {

View file

@ -1,3 +1,4 @@
import { validateCronExpression } from 'cron';
import { createZodDto } from 'nestjs-zod';
import { SystemConfig } from 'src/config';
import {
@ -43,7 +44,16 @@ const JobSettingsSchema = z
const cronExpressionSchema = z
.string()
.regex(/(((\d+,)+\d+|(\d+(\/|-)\d+)|\d+|\*) ?){5,7}/, 'Invalid cron expression')
.superRefine((value, ctx) => {
const validated = validateCronExpression(value);
if (!validated.valid) {
ctx.addIssue({
code: 'custom',
message: `Invalid cron expression. ${validated.error?.message ?? ''}`,
input: value,
});
}
})
.describe('Cron expression');
const DatabaseBackupSchema = z

View file

@ -319,14 +319,14 @@ describe(SystemConfigService.name, () => {
it('should accept valid cron expressions', async () => {
mocks.config.getEnv.mockReturnValue(mockEnvData({ configFile: 'immich-config.json' }));
mocks.systemMetadata.readFile.mockResolvedValue(
JSON.stringify({ library: { scan: { cronExpression: '0 0 * * *' } } }),
JSON.stringify({ library: { scan: { cronExpression: '0 0 */3 * *' } } }),
);
await expect(sut.getSystemConfig()).resolves.toMatchObject({
library: {
scan: {
enabled: true,
cronExpression: '0 0 * * *',
cronExpression: '0 0 */3 * *',
},
},
});