Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: encryption salt key is not any random string #25483

Merged
merged 2 commits into from
Oct 9, 2024
Merged
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
2 changes: 1 addition & 1 deletion bin/deploy-hobby
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export SENTRY_DSN="${SENTRY_DSN:-'https://[email protected]/1'}"
POSTHOG_SECRET=$(head -c 28 /dev/urandom | sha224sum -b | head -c 56)
export POSTHOG_SECRET

ENCRYPTION_SALT_KEYS=$(head -c 28 /dev/urandom | sha224sum -b | head -c 56)
ENCRYPTION_KEY=$(head -c 32 /dev/urandom | base64 | tr +/ -_ | tr -d =)
export ENCRYPTION_SALT_KEYS

# Talk to the user
Expand Down
20 changes: 16 additions & 4 deletions bin/upgrade-hobby
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,24 @@ else
fi

[[ -f ".env" ]] && export $(cat .env | xargs) || ( echo "No .env file found. Please create it with POSTHOG_SECRET and DOMAIN set." && exit 1)

# we introduced ENCRYPTION_SALT_KEYS and so if there isn't one, need to add it
# check for it in the .env file
if ! grep -q "ENCRYPTION_SALT_KEYS" .env
then
ENCRYPTION_SALT_KEYS=$(head -c 28 /dev/urandom | sha224sum -b | head -c 56)
echo "ENCRYPTION_SALT_KEYS=$ENCRYPTION_SALT_KEYS" >> .env
if ! grep -q "ENCRYPTION_SALT_KEYS" .env; then
ENCRYPTION_KEY=$(head -c 32 /dev/urandom | base64 | tr +/ -_ | tr -d =)
echo "ENCRYPTION_SALT_KEYS=$ENCRYPTION_KEY" >> .env
echo "Added missing ENCRYPTION_SALT_KEYS to .env file"
else
# Read the existing key
EXISTING_KEY=$(grep "ENCRYPTION_SALT_KEYS" .env | cut -d '=' -f2)

# Check if the existing key is in the correct format (32 bytes base64url)
if [[ ! $EXISTING_KEY =~ ^[A-Za-z0-9_-]{43}$ ]]; then
echo "ENCRYPTION_SALT_KEYS is not in the correct fernet format and will not work"
echo "🛑 Stop this script and do not proceed"
echo "remove ENCRYPTION_SALT_KEYS from .env and try again"
exit 1
fi
fi


Expand Down
Loading