Skip to content

Commit 8e84aec

Browse files
committed
Update cron-engine.sh
1 parent ec083ef commit 8e84aec

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

modules/cron/cron-engine.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,49 @@ log_message() {
77
echo "$(date '+%Y-%m-%d %H:%M:%S'): $1" >> "$CRON_LOG_FILE"
88
}
99

10+
# Validate command doesn't contain dangerous patterns
11+
validate_command() {
12+
local cmd="$1"
13+
# Block commands that could escape the container context
14+
if [[ "$cmd" =~ (^|[[:space:]])(rm[[:space:]]+-rf[[:space:]]+/[[:space:]]*$|dd[[:space:]]+if=|mkfs\.|:\(\)\{) ]]; then
15+
log_message "BLOCKED dangerous command pattern: $cmd"
16+
return 1
17+
fi
18+
return 0
19+
}
20+
1021
execute_if_match() {
1122
local minute="$1" hour="$2" day="$3" month="$4" weekday="$5" command="$6"
12-
23+
1324
# Get current time (portable version)
1425
local curr_min curr_hour curr_day curr_month curr_weekday
1526
curr_min=$(date '+%M' | sed 's/^0*//')
1627
curr_hour=$(date '+%H' | sed 's/^0*//')
1728
curr_day=$(date '+%d' | sed 's/^0*//')
1829
curr_month=$(date '+%m' | sed 's/^0*//')
1930
curr_weekday=$(date '+%w')
20-
31+
2132
# Fix empty values (when sed removes all chars)
2233
[[ -z "$curr_min" ]] && curr_min=0
2334
[[ -z "$curr_hour" ]] && curr_hour=0
2435
[[ -z "$curr_day" ]] && curr_day=0
2536
[[ -z "$curr_month" ]] && curr_month=0
26-
37+
2738
# Check if current time matches cron pattern
2839
[[ "$minute" != "*" && "$minute" != "$curr_min" ]] && return
2940
[[ "$hour" != "*" && "$hour" != "$curr_hour" ]] && return
3041
[[ "$day" != "*" && "$day" != "$curr_day" ]] && return
3142
[[ "$month" != "*" && "$month" != "$curr_month" ]] && return
3243
[[ "$weekday" != "*" && "$weekday" != "$curr_weekday" ]] && return
33-
34-
# Execute command
44+
45+
# Validate command before execution
46+
if ! validate_command "$command"; then
47+
return 1
48+
fi
49+
50+
# Execute command using bash -c for controlled execution
3551
log_message "Executing: $command"
36-
eval "$command" >> "$CRON_LOG_FILE" 2>&1
52+
/bin/bash -c "$command" >> "$CRON_LOG_FILE" 2>&1
3753
}
3854

3955
# Main cron loop

0 commit comments

Comments
 (0)