Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion bin/entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ fi

# Execute user startup script if it exists
if [[ -e ${USER_STARTUP_SCRIPT} ]]; then
bash ${USER_STARTUP_SCRIPT}
__ret=0
if [[ -x ${USER_STARTUP_SCRIPT} ]]; then
${USER_STARTUP_SCRIPT}
__ret=$?
else
chmod a+x ${USER_STARTUP_SCRIPT} || ls -l ${USER_STARTUP_SCRIPT}
${USER_STARTUP_SCRIPT}
__ret=$?
fi
Comment on lines +30 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix chmod failure handling and improve security.

The current implementation has several issues:

  1. Logic error: If chmod fails on line 34, the || ls -l runs for debugging, but execution continues to line 35 where the non-executable script will fail. The fallback should either exit or skip execution.

  2. Overly permissive: chmod a+x grants execute permission to all users. Use chmod +x instead.

  3. Missing quotes: ${USER_STARTUP_SCRIPT} should be quoted to handle paths with spaces.

Apply this diff to fix the issues:

 	__ret=0
 	if [[ -x ${USER_STARTUP_SCRIPT} ]]; then
-		${USER_STARTUP_SCRIPT}
+		"${USER_STARTUP_SCRIPT}"
 		__ret=$?
 	else
-		chmod a+x ${USER_STARTUP_SCRIPT} || ls -l ${USER_STARTUP_SCRIPT}
-		${USER_STARTUP_SCRIPT}
-		__ret=$?
+		if chmod +x "${USER_STARTUP_SCRIPT}"; then
+			"${USER_STARTUP_SCRIPT}"
+			__ret=$?
+		else
+			echo "ERROR: Failed to make user startup script executable" >&2
+			ls -l "${USER_STARTUP_SCRIPT}" >&2
+			__ret=1
+		fi
 	fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -x ${USER_STARTUP_SCRIPT} ]]; then
${USER_STARTUP_SCRIPT}
__ret=$?
else
chmod a+x ${USER_STARTUP_SCRIPT} || ls -l ${USER_STARTUP_SCRIPT}
${USER_STARTUP_SCRIPT}
__ret=$?
fi
__ret=0
if [[ -x ${USER_STARTUP_SCRIPT} ]]; then
"${USER_STARTUP_SCRIPT}"
__ret=$?
else
if chmod +x "${USER_STARTUP_SCRIPT}"; then
"${USER_STARTUP_SCRIPT}"
__ret=$?
else
echo "ERROR: Failed to make user startup script executable" >&2
ls -l "${USER_STARTUP_SCRIPT}" >&2
__ret=1
fi
fi
🤖 Prompt for AI Agents
In bin/entrypoint around lines 30 to 37, the block attempts to chmod and run the
USER_STARTUP_SCRIPT but has logic and security issues: replace chmod a+x with
chmod +x, quote "${USER_STARTUP_SCRIPT}" everywhere, and change the flow so that
after attempting chmod +x "${USER_STARTUP_SCRIPT}" you check its exit status and
if chmod fails run ls -l "${USER_STARTUP_SCRIPT}" and exit with a non-zero code
(or skip execution) instead of proceeding to run a non-executable file; finally
only execute the script if it is -x "${USER_STARTUP_SCRIPT}" and propagate its
exit code to __ret.

if [[ ${__ret} -ne 0 ]]; then
echo "WARN: User startup script exited with error code ${__ret}" >&2
fi
fi

# Redirect output to /dev/null unless in debug mode
Expand Down