Script scheduling. Licensed under AGPL-3.0-or-later.
What's new in v1.6.8
[1.6.8] - 2026-11-24
Security
- Script allowlist bypass via shell syntax in the command.
validate_commandonly compared the first word of a command with the approved script list, soapproved.pl; anything,approved.pl $(anything), a pipe,&&, backticks, or a newline (which starts a second crontab line) were all accepted and then run with the Koha instance's privileges. Commands are now tokenized (Cron::Script::parse_command) and only plain words, quoting, simple$NAMEreferences and file redirections (>/dev/null 2>&1) are accepted. - Crontab line injection through other free-text fields. A newline in a job's
name,description,schedule, or an environment variable name or value was written into the crontab verbatim and became a new, attacker-controlled crontab line. All of these are now validated as single-line (Cron::Job::validate_job_fields), environment variable names must be plain identifiers, andCron::Job::create_job_block-- the single write path for add, update and migrate -- refuses unsafe data as a last line of defence. - Environment variables that load code.
PERL5OPT,PERL5LIB,LD_*,PATH,BASH_ENV,PYTHON*,NODE_OPTIONSand similar can no longer be set on a job: they let an approved script load arbitrary code. - Enabling a job skipped all validation. Enabling a disabled job now re-validates its command against the approved list, its script's declared requirements, and its script policy (non-repeatable, allowed hours, required options), exactly as adding it would.
Anyone who can use the plugin (superlibrarians, or the configured user allowlist) could previously run arbitrary shell commands as the Koha user, defeating both allowlists. Upgrading is recommended for all installations.
Added
- Server-side enforcement of required positional arguments: a job whose command supplies fewer bare arguments than its script's
args => { min => N }declaration is rejected on add, update and enable, with the same wording core uses (At least 1 output_directory argument required (got 0)). Option values,--,--opt=value,--no-opt, short and legacy single-dash aliases, Getopt::Long's optional-value rule, and redirections are all accounted for when counting. - Parsed script options now include
aliasesandoptional_value.
Changed
- Commands containing shell syntax other than quoting,
$NAMEreferences and redirections are now rejected, including when migrating an existing system cron entry (for example one that pipes into another command). Such entries need to be wrapped in a script. - Migrated job descriptions built from multi-line crontab comments are now joined with spaces onto a single line.
- The OpenAPI spec now documents the
400response ofPOST /jobs/{job_id}/enable.
Changed
describe_optionsdetection is now anchored to a realKoha::Script->describe_options(call in executable code. Comments, POD, text after__END__, anddescribe_optionson other classes no longer divert a plain-GetOptionsscript onto the describe_options parser (which would have dropped its options). Verified against the nine core cron scripts converted so far.
Crontab
This is a plugin for Koha that simplifies the management of a koha instances local crontab.
We put the power in the hands of the user by exposing the local crontab to them as an administration tool plugin, allowing them to edit existing lines, schedules and environment as well as adding new jobs all from within the staff UI. Existing, unmanaged system crontab entries are shown for reference and can be migrated into plugin management with a single click.
Configuration
Configuration Page
The plugin provides a configuration page accessible via the "Configure" action in the Koha plugins interface. This page allows administrators to:
- User Allowlist: Restrict access to the plugin by specifying a comma-separated list of borrowernumbers using the build in user search picker
- Script Policy: Define which subset of KOHA_CRON commands/scripts are permitted to run, and optionally mark individual scripts as non-repeatable (only one scheduled instance at a time), restricted to specific hours of the day, or as requiring specific command-line options to have a value before a job can be saved (recommended for security)
- Logging: Toggle whether job add/edit/delete/enable/disable actions are recorded to Koha's action log
- Backup Retention: How many crontab backups to keep before older ones are pruned (default: 10)
Backups are kept outside the plugin so they survive uninstalling it (Koha deletes the plugin's own directory then): in koha-crontab-plugin/ under the backupdir set in koha-conf.xml (/var/spool/koha/<instance> on package installs) when the Koha user can write there, otherwise in .crontab_backups/ in the instance's directory (/var/lib/koha/<instance> on package installs). Only if neither is writable are they kept under the plugin's own directory, which is deleted on uninstall. Backups from older versions in the plugin directory are still listed.
Uninstalling the plugin leaves its jobs in the crontab as ordinary cron entries, and takes a final backup first when a backup directory is available.
Versions and restoring
The Versions tab lists the crontab backups (one per state, newest first), shows what changed against the current crontab, and can restore one. The current crontab is backed up before a restore, so it can be undone. A restore is checked like adding or enabling the jobs in it: a version containing a plugin-managed job that could not be saved today (script no longer permitted by the policy, unsupported command syntax, missing required option, repeated non-repeatable script, job-level environment variable) is refused and the reasons are shown.
Both allowlists can also be configured via the koha-conf.xml file (see below).
An empty script policy means no scripts can be scheduled. Nothing is permitted until the policy lists scripts (on the Configure page, or in a server policy file; see below). On a fresh install the plugin seeds a short list of the routine scheduled jobs librarians most often want to control (runreport.pl, longoverdue.pl, update_patrons_category.pl, process_message_queue.pl, holds/holds_reminder.pl) from default-policy.yaml inside the plugin. Scripts that can do a lot of damage with the wrong arguments (cleanup_database.pl, gather_print_notices.pl) are deliberately left out; add them yourself if you want them. The seed happens once, at install time: it can be freely edited from the Configure page afterwards, and upgrading never overwrites a policy you've already configured. If a server policy file is configured, nothing is seeded, because the server policy applies as written.
Chained steps and today's date
Chained steps
A job can run several commands in order, each only if the previous one succeeded (shell &&). That keeps the order even when an earlier step overruns its time slot, which two separate jobs scheduled an hour apart cannot promise. In the job form, build a command with the script browser and parameter builder, click Add as a step, and repeat; the steps can be reordered, edited and removed. Whatever is left in the command box when you save becomes the last step, so a one-command job works as it always has.
Example: Friday-evening patron expiry, delete first and then move the category, each using the day it runs:
$KOHA_CRON_PATH/delete_patrons.pl --category_code GS --expired_before=$(date +%F) --confirm$KOHA_CRON_PATH/update_patrons_category.pl --from=GS --to=EXPST --where "dateexpiry < '$(date +%F)'" --confirm
The chain is stored as an ordered list of steps (# @step-1:, # @step-2: comments in the job's block) and the plugin writes the && itself. Every step is checked on its own, exactly as a single command is: it must be an approved script, satisfy the script's required options and bare arguments, and respect non_repeatable and allowed_hours. A non_repeatable script can appear once per chain. A step that fails the check names itself ("Step 2: ...").
Over the REST API a job has either command (one command, unchanged) or steps (a list of up to 10 commands); sending both is refused. Responses always include steps; for a chain command is the rendered line, shown for display only (sending it back as command is refused because it contains &&).
Migrating a chained system entry. A system crontab entry that chains commands with && can be migrated into a job when every command in it is a script the policy permits; the commands become the steps. The line is split only at a && with whitespace on both sides, and each piece must then pass the same strict single-command check as any command, so a && inside quotes, ;, |, ||, a lone &, other substitution, or a single command the policy does not permit leaves the whole entry unmigratable (the error names the step). The plugin rewrites the line from its steps, so spacing around && is normalised; the job is named after its scripts (a.pl + b.pl).
Today's date: $(date +FORMAT) and $(date -d '-7 days' +FORMAT)
A command's arguments may contain $(date +FORMAT), replaced with the date or time each time the job runs, or $(date -d '-7 days' +FORMAT) for a date relative to it (for example --expired_before=$(date -d '-7 days' +%F) for "a week ago"). These two are the only command substitutions allowed, and they are fixed patterns, not general substitution:
- The command inside must be exactly
date +FORMATordate -d 'OFFSET' +FORMAT: no other command, nothing nested, and no other options (no-u,-f,-I,--date, a second-d). OFFSETis a sign (+or-), one to four digits, one space and one ofday,days,week,weeks,month,months,year,years, in single quotes:-d '-7 days',-d '+1 month'. It is not the free-text language GNU date's-dnormally accepts, so'7 days ago',yesterday,@epoch, time zones, hours/minutes/seconds, several offsets and unsigned numbers are all refused. Month and year arithmetic follows GNU date, so-1 monthfrom 31 March gives 3 March.FORMATstarts with a conversion and contains only numeric conversions (%Y %y %m %d %H %I %M %S %j %u %w %U %W %V %G %g %C %s, and the shorthands%F %T %D %R) and the separators- _ . : /and digits. Conversions that vary by locale or pad with spaces (%e %k %c %x %a %b),%n,%t,%%, flags (%-d) and any quoting are refused. The result is therefore always a single word with no spaces, glob characters or leading-.- It works bare or inside double quotes. It does not work inside single quotes (the shell would not expand it), so that is refused rather than silently doing nothing. It cannot be the script itself or part of an option's name (
--$(date +%s)=1).
In a crontab line a bare % means newline, so the plugin writes every % as \% and reads it back as %. You always type and see a plain %. A literal % elsewhere (--like 50%) works for the same reason.
What this does and does not allow
Allowed: several approved scripts joined with && by the plugin; $(date +FORMAT) as above; quoting, $NAME/${NAME} and redirections as before.
Still refused, in any step: ;, |, ||, a bare &, a typed &&, backticks, any other $(...), subshells, here-documents, newlines, job-level environment variables, a word starting with # (a shell comment would silently drop the rest of the line), and a script that is not on the policy. A job's line is trusted only while it is exactly what its recorded steps render to; a hand-edited chain is flagged, cannot be enabled, and is not restored from a backup.
Not changed: allowing a script allows whatever it can do with any arguments (see below), and a step's redirections (> file) can overwrite any file the Koha user can write.
Policy files
The script policy is a YAML document. The same schema is used by the server policy file (see koha_plugin_crontab_script_policy below) and is what the Configure page stores for the library policy. The shipped default-policy.yaml is a complete, commented example.
# Which scripts under $KOHA_CRON_PATH may be scheduled. A script not listed here
# cannot be added to the crontab through the plugin.
scripts:
- path: runreport.pl
- path: cleanup_database.pl
non_repeatable: true # only one scheduled instance at a time
allowed_hours: "0-5,22-23" # only run overnight
- path: longoverdue.pl
required_options: [lost, charge] # must be present in the command
- path: holds/holds_reminder.pl
path is relative to KOHA_CRON_PATH and names either a script or a directory:
- a script:
runreport.pl,holds/holds_reminder.pl, or just the file name (nightly.plcoversbatch/nightly.pl); - a directory, with or without a trailing slash:
batch/orbatchcovers everything under it, including subdirectories.
A path is not a string prefix: cleanup does not cover cleanup_database.pl, and batch does not cover batch_evil.pl. Matching is case-sensitive.
allowed_hours takes hours and ranges ("2", "0-5", "0-5,22-23").
Server-managed policy (for administrators)
If you run Koha for several libraries, or manage it with configuration management such as Ansible, you can set the script policy from a file on the server instead of leaving it to staff on the Configure page. The file uses the same schema as above and is the policy of record: staff can narrow it but never widen it.
-
Write the policy file somewhere the Koha instance user can read, but not write (so staff cannot alter it through the plugin):
# /etc/koha/plugins/crontab-script-policy.yaml scripts: - path: process_message_queue.pl - path: holds/holds_reminder.pl - path: cleanup_database.pl non_repeatable: true allowed_hours: "0-5" required_options: [sessions] -
Point the plugin at it in the instance's
koha-conf.xml, inside the<config>block, and restart Plack:<koha_plugin_crontab_script_policy>/etc/koha/plugins/crontab-script-policy.yaml</koha_plugin_crontab_script_policy>
How it combines with the library policy edited on the Configure page:
- Scripts: only scripts the server file lists can be scheduled. A script it doesn't list is refused no matter what the library policy says, and an empty or unconfigured library policy does not unlock everything (nor does it lock everything out: it inherits the server file). The library policy can only select a subset.
- Unconfigured or empty library policy: the server file applies as written. On install the plugin does not seed its own default list when a server file is configured, so there is nothing to narrow it.
- Constraints:
non_repeatableandrequired_optionsset by the server file always apply, and the library policy can only add to them.allowed_hourscan only be narrowed, to the hours both allow. - Directories: an entry naming a directory (for example
batch/) offers every script under it. Entries name scripts or directories, never a bare string prefix. - Selecting individual scripts under a directory: if the server file lists
batch/, the library policy can selectbatch/nightly.pl(or a narrower directory such asbatch/sub/) from it. Anynon_repeatable,allowed_hoursandrequired_optionson the server's directory entry apply to the scripts chosen under it. - The Configure page shows what the server permits: with a server policy file, the script picker still lists every script, but the ones the server leaves out are shown in red and can't be selected, free typing is turned off, and a banner at the top of the page explains this. A saved selection the server no longer permits is flagged as ignored.
- No restart needed for edits: the file is read on every request, so changing it (an Ansible run, for instance) takes effect immediately. Only changing the
koha-conf.xmlsetting needs a restart.
An Ansible sketch:
- name: Crontab plugin script policy
ansible.builtin.copy:
dest: /etc/koha/plugins/crontab-script-policy.yaml
owner: root
group: "{{ koha_instance }}-koha"
mode: "0640"
content: |
scripts:
{% for script in crontab_plugin_scripts %}
- path: {{ script.path }}
{% if script.non_repeatable | default(false) %}
non_repeatable: true
{% endif %}
{% endfor %}
- name: Point the plugin at it
community.general.xml:
path: "/etc/koha/sites/{{ koha_instance }}/koha-conf.xml"
xpath: /yazgfs/config/koha_plugin_crontab_script_policy
value: /etc/koha/plugins/crontab-script-policy.yaml
notify: restart plack
Environment variables
Jobs cannot set environment variables. In a crontab an environment line is not scoped to the job next to it: it stays in effect for every entry that follows it in the file, managed by this plugin or not, until it is set again. A "per-job" MAILTO= would silently redirect the output of every later job, and a KOHA_CRON_PATH or PERL5OPT could redirect or hijack every script that follows.
Set variables once, in the crontab header, where they are explicit. They are shown read-only on the plugin's page.
A job that already carries environment variables (from an older version, or a hand-edited crontab) keeps working, and the variables can be removed from the job's edit form, but none can be added or changed.
koha-conf.xml Settings
This plugin can accept some settings stored in the koha configuration file, inside the config block.
koha_plugin_crontab_cronfile
<koha_plugin_crontab_cronfile>/etc/cron.d/koha-mylibrary</koha_plugin_crontab_cronfile>
By default the plugin will use the Koha user's crontab. If this option is set, it will use this file instead.
koha_plugin_crontab_script_policy
<koha_plugin_crontab_script_policy>/etc/koha/plugins/crontab-script-policy.yaml</koha_plugin_crontab_script_policy>
If set, points to a YAML file defining a server-enforced ceiling on which scripts may be scheduled and what scheduling constraints apply to them. The library's own Script Policy setting (configured via the Configure page) can only select a subset of what this file allows, can only tighten (never loosen) any non_repeatable/allowed_hours it sets, and can only add to (never remove from) any required_options it sets. If this option is not set, the library's Script Policy setting alone governs, as before.
koha_plugin_crontab_user_allowlist
<koha_plugin_crontab_user_allowlist>1,2,3</koha_plugin_crontab_user_allowlist>
This option, if set, will allow only the users whose borrowernumbers are listed to access the plugin
even if the patron has the admin plugins permission.
Security Considerations
IMPORTANT: This plugin executes shell commands with instance-level permissions. Please observe the following security best practices:
What the script policy does and does not limit
The script policy limits which scripts can be scheduled, and can require options (required_options), restrict hours and prevent duplicate instances. It does not restrict the values of a script's arguments, and it is not a sandbox: an allowlisted script can do anything it can do, with any arguments, as the Koha user. Treat access to the plugin as equivalent to running the allowlisted scripts yourself. In particular:
runreport.pl(in the defaults) runs any saved report and can email or SFTP its output (--to,--from,--sftp-dest-id), so it can read whatever a saved report can read.cleanup_database.pldeletes data by age, including Koha's action logs (--logs) and sessions. A job with a short retention shortens the audit trail, including the entries this plugin writes when logging is enabled.gather_print_notices.plwrites files to whatever directory it is given, anywhere the Koha user can write.
Remove any script from the policy that the people who can use the plugin shouldn't be able to use this way, and keep the user allowlist (below) tight.
Permission Management
-
Configure Plugins Permission (
plugins_tool_configure): Users with this permission can:- Modify the user allowlist (controlling who can use the plugin)
- Modify the command allowlist (controlling which scripts can be executed)
- Recommendation: Severely restrict this permission to only the most trusted administrators
-
Use Administrative Plugins Permission (
plugins_tool_admin): Users need only this permission to:- Create, edit, enable/disable, and delete scheduled jobs
- Use the plugin's core functionality
- Recommendation: Grant this permission to staff who need to manage cron jobs
Additional Security Measures
- Always configure the user allowlist to restrict access to trusted staff only
- Use the command allowlist to define which scripts and commands are permitted to run
- Use absolute paths for all commands (e.g.,
/usr/bin/perl /path/to/script.pl) - Regular audits: Review configured jobs periodically to ensure no unauthorized commands are present
- Monitor logs: Check
cron_manager.logfor suspicious activity
Installation
Enable the plugin system
To set up the Koha plugin system you must first make some changes to your install.
- Change
<enable_plugins>0<enable_plugins>to<enable_plugins>1</enable_plugins>in your koha-conf.xml file - Confirm that the path to
<pluginsdir>exists, is correct, and is writable by the web server - Add the pluginsdir to your apache PERL5LIB paths and koha-plack startup scripts PERL5LIB
- Restart your webserver
Once set up is complete you will need to alter your UseKohaPlugins system preference.
Dependencies
This plugin requires Koha 25.05 or later.
This plugin has no external dependencies. All required modules (Config::Crontab, UUID) are either bundled with the plugin or already available in Koha core.
Download and install the plugin
The latest releases of this plugin can be obtained from the release page where you can download the relevant *.kpz file
Development
Setup, testing and the release process are documented in DEVELOPMENT.md.
License
This plugin is licensed under the GNU Affero General Public License, version 3 or any later version (AGPL-3.0-or-later). Each source file carries an SPDX-License-Identifier header stating this.
The bundled copy of Config::Crontab in Koha/Plugin/Com/OpenFifth/Crontab/lib is by Scott Wiersdorf and is distributed under the same terms as Perl itself; it keeps its own licence notice.
Technical report — v1.6.8 (what do these checks mean?)
| Check | Required | Result | Message |
|---|---|---|---|
| changelog_format | Advisory | Passed | |
| dependency_allowlist | Required | Passed | |
| docs_presence | Advisory | Passed | |
| gpg_signed_tag | Advisory | Passed | |
| hardcoded_credentials | Advisory | Passed | |
| koha_max_version | Advisory | Failed | metadata does not declare maximum_version (recommended, does not block publishing) |
| manifest_completeness | Required | Passed | |
| perl_critic | Advisory | Failed | "return" statement with explicit "undef" at line 567, column 5. See page 199 of PBP.; "return" statement with explicit "undef" at line 589, column 5. See page 199 of PBP.; "%is_negatable" is declared but not used at line 1041, column 5. Unused variables clutter code and make it harder to read.; Two-argument "open" used at line 93, column 2. See page 207 of PBP.; Two-argument "open" used at line 113, column 2. See page 207 of PBP.; Subroutine "new" called using indirect syntax at line 148, column 19. See page 349 of PBP.; Two-argument "open" used at line 288, column 2. See page 207 of PBP.; Subroutine "new" called using indirect syntax at line 1385, column 17. See page 349 of PBP.; Subroutine "new" called using indirect syntax at line 1389, column 20. See page 349 of PBP.; Subroutine "new" called using indirect syntax at line 1392, column 20. See page 349 of PBP.; Stricture disabled at line 1467, column 3. See page 429 of PBP.; Stricture disabled at line 3191, column 2. See page 429 of PBP. |
| perl_syntax | Required | Passed | |
| plugin_template_wrapper | Advisory | Passed | |
| readme_presence | Advisory | Passed | |
| tests_presence | Advisory | Passed | |
| translatable_templates | Advisory | Failed | Template(s) render text but never use the [% t(...) %] translation marker: Koha/Plugin/Com/OpenFifth/Crontab/crontab.tt, Koha/Plugin/Com/OpenFifth/Crontab/configure.tt |