Skip to content

Commit a195261

Browse files
committed
fix(auth): fail fast on blank JWT key + libargon2-dev in Dockerfile
jwt 3.2.0 rejects nil/empty HMAC keys (CVE-2026-45363) if JWT_SECRET_KEY and secret_key_base are both absent, the old code would silently use nil and produce cryptic 401s at request time. Now raises at boot so Coolify catches it in deploy logs, not in prod. - jwt_service.rb: tap guard raises on blank SECRET_KEY at class load - Dockerfile: add libargon2-dev (required native dep for argon2 gem) - codeql.yml: add pull-requests: write (403 when commenting on PRs
1 parent 4340fa7 commit a195261

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

.github/workflows/codeql.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ on:
3030

3131
permissions:
3232
security-events: write # upload SARIF para o Security tab
33+
pull-requests: write # postar comentario de resumo no PR
3334
packages: read
3435
actions: read
3536
contents: read

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RUN apt-get update -qq && apt-get install -y --no-install-recommends \
88
build-essential \
99
libpq-dev \
1010
libyaml-dev \
11+
libargon2-dev \
1112
git \
1213
tzdata \
1314
curl \

app/modules/authentication/services/jwt_service.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
# - Requires TokenBlacklist model with methods: blacklisted?(jti), add_to_blacklist(jti, expires_at)
88
# - Requires User model with attributes: id, organization_id, role, email
99
class JwtService
10-
SECRET_KEY = ENV.fetch('JWT_SECRET_KEY') { Rails.application.secret_key_base }
10+
# jwt >= 3.2.0 rejects nil/empty HMAC keys (CVE-2026-45363).
11+
# Raise at boot time so a missing env var is caught immediately, not at first request.
12+
SECRET_KEY = ENV.fetch('JWT_SECRET_KEY') { Rails.application.secret_key_base }.tap do |key|
13+
raise 'JWT_SECRET_KEY / secret_key_base must not be blank' if key.blank?
14+
end
1115
EXPIRATION_HOURS = ENV.fetch('JWT_EXPIRATION_HOURS', 24).to_i
1216
REFRESH_EXPIRATION_DAYS = ENV.fetch('JWT_REFRESH_EXPIRATION_DAYS', 7).to_i
1317

0 commit comments

Comments
 (0)