Repository navigation
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a fresh self-hosted server set up from
example.env, nobody can create an account.What users see
example.envshipsTOS_URL=andPRIV_URL=blank, and docker-compose loads it withenv_file: ".env", so the server seesTOS_URLas 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.TRUSTED_DOMAINS=rejects every email address ("You are not authorized to use this server"). The shippedTRUSTED_DOMAINS=farmbot.io,farm.botline does the same for every non-FarmBot address, and it also stops the "Demo the app" button (its@farmbot.guestuser 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".NO_EMAILSset to anything excepttrue/false/1/0, such asyes,onor a blankNO_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 toNO_EMAILS. WithNO_EMAILS=false, email verification is silently skipped anyway.Cause
Ruby treats
""(and any string) as true, while the frontend treats""as false:Auth::ConsentHelpers#maybe_validate_tosdoesreturn unless User::ENFORCE_TOS, so with""it goes on to requireagree_to_terms, which the form never sets.EmailDomainHelpers#domain_is_ok?doesENV["TRUSTED_DOMAINS"] ? allowed_domains.include?(...) : true, and"".split(",")is[].UsersController#user_paramspasses the rawNO_EMAILSstring asskip_email, whichUsers::Createdeclares asboolean. The mutations boolean filter only accepts true/false/"true"/"false"/"1"/"0" and rejects anything else.User#verified?,TokensController,DevicesController.send_emailsandUsers::Update#skip_email_stuffall check the raw value for truthiness, so"false"still counts as on there.Changes
app/models/user.rb: addUser.env_setting(key)(ENV[key].presence, so blank means unset) andUser.env_flag(key)(true only fortrue/1/yes/on, any case; anything else, blank or unset is false).ENFORCE_TOSandSKIP_EMAIL_VALIDATIONuse them, soSKIP_EMAIL_VALIDATIONis 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 blankTRUSTED_DOMAINSmeans no restriction, the same as unset.app/mutations/users/update.rb,app/controllers/api/devices_controller.rb: readNO_EMAILSthroughUser.env_flagtoo, so all the places agree on what the value means.example.env: comment out theTRUSTED_DOMAINS=farmbot.io,farm.botexample (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 valuesNO_EMAILSaccepts, and say that blankTOS_URL/PRIV_URLskips the consent step.spec/models/user_spec.rbcoversenv_setting(blank and whitespace give nil) andenv_flag(on, off, blank and unset values).spec/mutations/users/create_spec.rbchecks that a blankTRUSTED_DOMAINSlets any address sign up, and that a parsedNO_EMAILS=yespasses theskip_emailfilter.The frontend already treats a blank
TOS_URLas "no terms", so this makes the backend match it. An existingNO_EMAILS=TRUE(the shipped value) or an unsetNO_EMAILSbehaves exactly as before. The only change in meaning is thatNO_EMAILS=false/0/nonow 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 .envsetup. They no longer have to find out which blank line in.envis blocking signup, and then restart every container because these values are read when the classes load.Testing: I wasn't able to run
rspeclocally (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 whichconst_reassignENFORCE_TOSandSKIP_EMAIL_VALIDATIONdon't depend on the old string values.🤖 Generated with Claude Code