mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 08:21:35 +00:00
fix(docker): validate timezone in runtime image (#116153)
This commit is contained in:
@@ -409,9 +409,16 @@ contains_disallowed_chars() {
|
||||
[[ "$value" == *$'\n'* || "$value" == *$'\r'* || "$value" == *$'\t'* ]]
|
||||
}
|
||||
|
||||
is_valid_timezone() {
|
||||
is_valid_timezone_in_image() {
|
||||
local value="$1"
|
||||
[[ -e "/usr/share/zoneinfo/$value" && ! -d "/usr/share/zoneinfo/$value" ]]
|
||||
docker run --rm --network none --entrypoint node "$IMAGE_NAME" -e '
|
||||
const timezone = process.argv[1];
|
||||
try {
|
||||
new Intl.DateTimeFormat("en", { timeZone: timezone }).format(0);
|
||||
} catch {
|
||||
process.exit(1);
|
||||
}
|
||||
' "$value"
|
||||
}
|
||||
|
||||
validate_mount_path_value() {
|
||||
@@ -497,9 +504,6 @@ if [[ -n "$TIMEZONE" ]]; then
|
||||
if [[ ! "$TIMEZONE" =~ ^[A-Za-z0-9/_+\-]+$ ]]; then
|
||||
fail "OPENCLAW_TZ must be a valid IANA timezone string (e.g. Asia/Shanghai)."
|
||||
fi
|
||||
if ! is_valid_timezone "$TIMEZONE"; then
|
||||
fail "OPENCLAW_TZ must match a timezone in /usr/share/zoneinfo (e.g. Asia/Shanghai)."
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$OPENCLAW_CONFIG_DIR"
|
||||
@@ -782,6 +786,10 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "$TIMEZONE" ]] && ! is_valid_timezone_in_image "$TIMEZONE"; then
|
||||
fail "OPENCLAW_TZ must be supported by $IMAGE_NAME (e.g. Asia/Shanghai)."
|
||||
fi
|
||||
|
||||
# Ensure bind-mounted data directories are writable by the container's `node`
|
||||
# user (uid 1000). Host-created dirs inherit the host user's uid which may
|
||||
# differ, causing EACCES when the container tries to mkdir/write.
|
||||
|
||||
Reference in New Issue
Block a user