Skip to content

Commit 0eb94af

Browse files
ihabadhamclaude
andcommitted
Guard against dev-default RENDERER_PASSWORD in production
The Pro renderer's JS side raises if RENDERER_PASSWORD is unset in production, but accepts the literal "local-dev-renderer-password" value. A CP secret misconfigured to that string (easy to happen when copying from .env.example) would let both sides "match" while running with no real authentication. Split the branch by Rails.env.local?: - dev/test keeps the .presence || default fallback so blank env vars still work for local development - production fetches strict and raises if blank, unset, or the literal dev default Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9518acd commit 0eb94af

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

config/initializers/react_on_rails_pro.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,25 @@
1212

1313
config.renderer_url = ENV.fetch("RENDERER_URL", "http://localhost:3800")
1414

15-
# Must match the password in renderer/node-renderer.js. Use .presence so
16-
# a blank value (e.g. the literal `RENDERER_PASSWORD=` that ships in
17-
# .env.example) falls back to the dev default. ENV.fetch would leave
18-
# Rails with "" while the renderer treats "" as unset via `||`,
19-
# producing a silent auth mismatch.
20-
config.renderer_password = ENV["RENDERER_PASSWORD"].presence || "local-dev-renderer-password"
15+
# Must match the password in renderer/node-renderer.js.
16+
#
17+
# Dev/test: blank or unset falls back to the dev default, so .env.example's
18+
# literal `RENDERER_PASSWORD=` still works. `.presence` matches the JS
19+
# side's `||` fallback (which treats "" as falsy).
20+
#
21+
# Production: raise loudly if blank, unset, or still the dev default. The
22+
# Pro renderer's JS side guards against unset in production but accepts
23+
# the literal dev-default value. If someone set the CP secret to the
24+
# well-known dev password, both sides would "match" but renderer auth
25+
# would be effectively disabled. This closes that gap.
26+
config.renderer_password =
27+
if Rails.env.local?
28+
ENV["RENDERER_PASSWORD"].presence || "local-dev-renderer-password"
29+
else
30+
pw = ENV["RENDERER_PASSWORD"]
31+
if pw.blank? || pw == "local-dev-renderer-password"
32+
raise "RENDERER_PASSWORD must be set to a non-empty, non-default value in production"
33+
end
34+
pw
35+
end
2136
end

0 commit comments

Comments
 (0)