Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions registry/coder/modules/code-server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ variable "open_in" {
}
}

variable "trusted_domains" {
type = list(string)
description = "A list of trusted domains for link protection. These domains will be added to the --link-protection-trusted-domains option."
default = []
}

resource "coder_script" "code-server" {
agent_id = var.agent_id
display_name = "code-server"
Expand All @@ -168,6 +174,7 @@ resource "coder_script" "code-server" {
EXTENSIONS_DIR : var.extensions_dir,
FOLDER : var.folder,
AUTO_INSTALL_EXTENSIONS : var.auto_install_extensions,
TRUSTED_DOMAINS : join(",", var.trusted_domains),
})
run_on_start = true

Expand Down
13 changes: 12 additions & 1 deletion registry/coder/modules/code-server/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,21 @@ if [ -n "${EXTENSIONS_DIR}" ]; then
mkdir -p "${EXTENSIONS_DIR}"
fi

# Set trusted domains argument
TRUSTED_DOMAINS_ARG=""
if [ -n "${TRUSTED_DOMAINS}" ]; then
# Split comma-separated domains and create multiple --link-protection-trusted-domains arguments
for domain in $(echo "${TRUSTED_DOMAINS}" | tr ',' ' '); do
Comment on lines +19 to +20
Copy link

Copilot AI Oct 16, 2025

Choose a reason for hiding this comment

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

This approach is vulnerable to word splitting and glob expansion issues. If a domain contains spaces or shell metacharacters, it will be incorrectly parsed. Use a more robust parsing method or validate input format.

Suggested change
# Split comma-separated domains and create multiple --link-protection-trusted-domains arguments
for domain in $(echo "${TRUSTED_DOMAINS}" | tr ',' ' '); do
# Split comma-separated domains safely and create multiple --link-protection-trusted-domains arguments
IFS=',' read -ra domains <<< "${TRUSTED_DOMAINS}"
for domain in "${domains[@]}"; do

Copilot uses AI. Check for mistakes.
if [ -n "$domain" ]; then
TRUSTED_DOMAINS_ARG="$TRUSTED_DOMAINS_ARG --link-protection-trusted-domains=$domain"
fi
done
fi

function run_code_server() {
echo "👷 Running code-server in the background..."
echo "Check logs at ${LOG_PATH}!"
$CODE_SERVER "$EXTENSION_ARG" --auth none --port "${PORT}" --app-name "${APP_NAME}" > "${LOG_PATH}" 2>&1 &
$CODE_SERVER $EXTENSION_ARG $TRUSTED_DOMAINS_ARG --auth none --port "${PORT}" --app-name "${APP_NAME}" > "${LOG_PATH}" 2>&1 &
}

# Check if the settings file exists...
Expand Down