Skip to content

Signup: treat blank TOS_URL / TRUSTED_DOMAINS as unset and parse NO_EMAILS as a real boolean - #2530

Open
tencur wants to merge 1 commit into
FarmBot:stagingfrom
tencur:fix/signup-blank-env-settings
Open

tencur wants to merge 1 commit into
FarmBot:stagingfrom
tencur:fix/signup-blank-env-settings

Conversation

@tencur

@tencur tencur commented Nov 17, 2026

Copy link
Copy Markdown

On a fresh self-hosted server set up from example.env, nobody can create an account.

What users see

  1. example.env ships TOS_URL= and PRIV_URL= blank, and docker-compose loads it with env_file: ".env", so the server sees TOS_URL as an empty string. The signup form shows no terms checkbox, but every signup fails with "Terms of service: you must agree to the terms of use." There is no way to tick a box that isn't there, and no other way to create the first user outside a Rails console.
  2. A blank TRUSTED_DOMAINS= rejects every email address ("You are not authorized to use this server"). The shipped TRUSTED_DOMAINS=farmbot.io,farm.bot line does the same for every non-FarmBot address, and it also stops the "Demo the app" button (its @farmbot.guest user is rejected, so the spinner never finishes). The comment says to delete it only "IF YOU RUN A PUBLIC SERVER", which someone running a private server reads as "keep it".
  3. NO_EMAILS set to anything except true/false/1/0, such as yes, on or a blank NO_EMAILS= to turn emails back on, also blocks every signup, this time with "Skip email isn't a boolean" (or "can't be blank"). Nothing links that message to NO_EMAILS. With NO_EMAILS=false, email verification is silently skipped anyway.

Cause

Ruby treats "" (and any string) as true, while the frontend treats "" as false:

# app/models/user.rb
ENFORCE_TOS = ENV.fetch("TOS_URL", false)            # "" -> TOS enforced
SKIP_EMAIL_VALIDATION = ENV.fetch("NO_EMAILS", false) # raw string
// frontend/front_page/front_page.tsx
if (globalConfig.TOS_URL) { return <TermsCheckbox ... /> }  // "" -> no checkbox

Auth::ConsentHelpers#maybe_validate_tos does return unless User::ENFORCE_TOS, so with "" it goes on to require agree_to_terms, which the form never sets. EmailDomainHelpers#domain_is_ok? does ENV["TRUSTED_DOMAINS"] ? allowed_domains.include?(...) : true, and "".split(",") is []. UsersController#user_params passes the raw NO_EMAILS string as skip_email, which Users::Create declares as boolean. The mutations boolean filter only accepts true/false/"true"/"false"/"1"/"0" and rejects anything else. User#verified?, TokensController, DevicesController.send_emails and Users::Update#skip_email_stuff all check the raw value for truthiness, so "false" still counts as on there.

Changes

  • app/models/user.rb: add User.env_setting(key) (ENV[key].presence, so blank means unset) and User.env_flag(key) (true only for true/1/yes/on, any case; anything else, blank or unset is false). ENFORCE_TOS and SKIP_EMAIL_VALIDATION use them, so SKIP_EMAIL_VALIDATION is now always a real boolean. That fixes both signup and the truthiness checks that read the constant.
  • app/mutations/users/email_domain_helpers.rb: a blank TRUSTED_DOMAINS means no restriction, the same as unset.
  • app/mutations/users/update.rb, app/controllers/api/devices_controller.rb: read NO_EMAILS through User.env_flag too, so all the places agree on what the value means.
  • example.env: comment out the TRUSTED_DOMAINS=farmbot.io,farm.bot example (most self-hosted servers want any address to be able to sign up; the comment says to set it on a server that can be reached from the internet), describe the values NO_EMAILS accepts, and say that blank TOS_URL/PRIV_URL skips the consent step.
  • Specs: spec/models/user_spec.rb covers env_setting (blank and whitespace give nil) and env_flag (on, off, blank and unset values). spec/mutations/users/create_spec.rb checks that a blank TRUSTED_DOMAINS lets any address sign up, and that a parsed NO_EMAILS=yes passes the skip_email filter.

The frontend already treats a blank TOS_URL as "no terms", so this makes the backend match it. An existing NO_EMAILS=TRUE (the shipped value) or an unset NO_EMAILS behaves exactly as before. The only change in meaning is that NO_EMAILS=false/0/no now really leaves email verification on.

Why it matters for self-hosting: someone who runs the server on their own LAN, with no terms page, no email domain and often no mail server, can now create their first account straight from the documented cp example.env .env setup. They no longer have to find out which blank line in .env is blocking signup, and then restart every container because these values are read when the classes load.

Testing: I wasn't able to run rspec locally (no Ruby toolchain on the machine I used), so the new examples haven't been run. I'd appreciate CI confirmation. I checked by reading the code that the existing specs which const_reassign ENFORCE_TOS and SKIP_EMAIL_VALIDATION don't depend on the old string values.

🤖 Generated with Claude Code

…MAILS as a real boolean

On a fresh self-hosted server set up from `example.env`, nobody can create an account.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant