Skip to content

Reject malformed numbers in cron schedule fields - #458

Open
leninworld wants to merge 1 commit into
useagenthq:mainfrom
leninworld:reject-malformed-cron-numbers
Open

leninworld wants to merge 1 commit into
useagenthq:mainfrom
leninworld:reject-malformed-cron-numbers

Conversation

@leninworld

@leninworld leninworld commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #309

What changed

  • expandField in backend/src/schedules/cron.ts read each value, range end and step with Number(), so an empty side counted as 0 and hex, exponent, sign and decimal forms were accepted. -5 * * * * was saved as minutes 0 to 5, /15 * * * * as every 15 minutes, and 0x1E 9 * * * as 9:30.
  • Values, range ends and steps must now be plain digits (/^\d+$/) before they are read. An empty side of a range and an empty value before / fail the same check. Valid expressions, including *, */n, a-b/n, a/n and leading zeros like 00 09 * * *, read as before.
  • Schedule create, update and next-runs preview (schedules/service.ts) and bot import (bots/transfer.ts) all validate through isValidCron, so they now reject these expressions too.

Testing

isValidCron before and after:

Expression Before After
-5 * * * *, /15 * * * *, 0- * * * *, * * * * -1 (empty side) valid invalid
0x1E 9 * * *, 1e1 * * * *, */1e1 * * * *, +5 * * * * valid invalid
*/+5 * * * *, 1.0 * * * *, 1,0x2 * * * * valid invalid
* * * * *, */15 * * * *, 0-30/5 9-17 * * 1-5, 5/10 * * * *, 0 0 1,15 * *, 00 09 * * * valid valid
  • bun test --timeout 30000 ./backend/test/schedules-cron.test.ts (from the repo root): 27 pass, 0 fail. On main the extended "rejects malformed expressions" test fails (26 pass, 1 fail). It now holds the issue's eight expressions plus three sibling forms: a signed step, a decimal and a hex value inside a comma list.
  • Dropping any one of the three digit checks (step, range ends, single value) makes that test fail again.
  • bunx -p typescript@5.9.3 tsc --noEmit in backend (after installing each package's deps, as CI does) and bun test scripts/agent-docs.test.ts: pass.

Not checked: I did not run the full backend suite (it needs the Postgres test database) or create a schedule in the app; the change is in the validator that those four paths call.

One effect to know: a schedule already saved with one of these expressions now reads as invalid, so the matcher no longer fires it (the same as any other invalid cron). I did not add a migration for such rows.


Start Proof
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject malformed numbers in cron schedule fields

1 participant