Skip to content

Commit ac274bf

Browse files
committed
fix: move HP_SHARED_KEY validation after strip_quotes and stop rejecting apostrophes
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
1 parent cdb586a commit ac274bf

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

start.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,23 @@ if [ "$NON_ASCII_COUNT" -gt 0 ]; then
123123
exit 1
124124
fi
125125

126-
# Reject characters that break the generated FRP TOML config or get mangled by
127-
# strip_quotes:
128-
# " - terminates the TOML basic string used for metadatas.token
126+
# Strip surrounding quotes if user accidentally included them in env vars
127+
HP_SHARED_KEY="$(strip_quotes "$HP_SHARED_KEY")"
128+
export HP_SHARED_KEY
129+
130+
# After stripping any surrounding quotes, the remaining value must not contain
131+
# characters that would corrupt the generated FRP TOML config line
132+
# `metadatas.token = "..."`:
133+
# " - terminates the TOML basic string
129134
# \ - starts a TOML escape sequence inside that string
130-
# ' - silently stripped from the end of the value by strip_quotes() below
131-
FORBIDDEN_COUNT=$(printf '%s' "$HP_SHARED_KEY" | LC_ALL=C tr -cd "\"\\\\'" | wc -c)
135+
FORBIDDEN_COUNT=$(printf '%s' "$HP_SHARED_KEY" | LC_ALL=C tr -cd '"\\' | wc -c)
132136
if [ "$FORBIDDEN_COUNT" -gt 0 ]; then
133137
echo "ERROR: HP_SHARED_KEY contains a forbidden character."
134-
echo "The following characters are not allowed: double quote (\"), single quote ('), backslash (\\)."
138+
echo "The following characters are not allowed: double quote (\"), backslash (\\)."
135139
echo "Please choose a password without these characters."
136140
exit 1
137141
fi
138142

139-
# Strip surrounding quotes if user accidentally included them in env vars
140-
HP_SHARED_KEY="$(strip_quotes "$HP_SHARED_KEY")"
141-
export HP_SHARED_KEY
142-
143143
# Strip surrounding quotes from other commonly affected environment variables
144144
NC_INSTANCE_URL="$(strip_quotes "$NC_INSTANCE_URL")"
145145
HP_FRP_ADDRESS="$(strip_quotes "$HP_FRP_ADDRESS")"

0 commit comments

Comments
 (0)