Repository navigation
Make auto-login from BCC referrers work again - #238
Merged
Merged
Conversation
The front-page script read document.referer, which is undefined, so it threw a TypeError whenever the visitor had a referrer. Since August 2023 only the "logged in before on this device" cookie has logged anyone in. It now reads document.referrer, and it ignores links within the site, so a visitor on a site whose own domain starts with "bcc" is not sent to log in when they click Home. The server-side check ran on init, where is_front_page() is always false, so it has never logged anyone in since April 2023. It is removed rather than moved: it had no once-per-session guard, matched "bcc" anywhere in the referrer's host, and would only run when the page cache misses. The script does the same job from cached pages. Closes #237 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the referrer-based front-page auto-login change.
No open issues 🎉
What changed in this PR
Restores referrer-based front-page auto-login in BCC Login, addressing #237 while keeping the existing wp-login.php redirect unchanged.
Changes:
- Fixes the
document.referrertypo that prevented referrer-based auto-login. - Excludes same-host navigation from the referrer check.
- Removes the ineffective server-side auto-login check, retaining the browser’s once-per-tab-session guard.
| File | Description |
|---|---|
plugins/bcc-login/bcc-login.php |
Repairs browser referrer checks and removes the unused server-side auto-login path. |
Review effort: Balanced
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.
Closes #237.
Changes
Referrer typo fixed. The front-page script read
document.referer(undefined), so it threw a TypeError for every visitor with a referrer. It has been broken since August 2023 (cbfbe30). Until now, only thewp_has_logged_incookie ("logged in before on this device") triggered auto-login. Visitors coming from portal.bcc.no, brunstad.org or a host starting withbccwere never logged in.Links within the site are ignored. Without this, fixing the typo would send a logged-out visitor on a site whose own domain starts with "bcc" to the login page when they click Home from an inner page. The script now skips the referrer check when the referrer is the site itself.
Server-side auto-login removed.
should_auto_login()ran oninit, whereis_front_page()is always false (the main query hasn't run yet), so it has never fired since April 2023 (745babf). I removed it instead of moving it totemplate_redirect, as Auto-login via referrer and server-side never triggers #237 suggests. Moving it would turn on behaviour we don't want:sessionStorageflag. Anyone with the 10-yearwp_has_logged_incookie would be sent to login.bcc.no on every front-page visit and could never see the public front page without logging in.bccanywhere in the referrer's host, which is broader than the script's check.The
wp-login.php→ login.bcc.no redirect is unchanged.Behaviour change to be aware of
Referrer-based auto-login has effectively been off for about three years and is now back on. A visitor who comes from a matching host and isn't logged in to BCC SSO lands on the login page once per tab session, instead of the public front page. That includes the public sites brunstad.org and anything starting with
bcc(e.g. bcc.media). If that's too broad, we can narrow$auto_login_referrershere or in a follow-up.Testing
Ran the script from the rendered front page through a fake
document,locationandsessionStoragein node, against v1.2.19 and this branch. The site's host in the test isbcc-test.no:/loginbcc-test.no/loginwith only the typo fixed)wp_has_logged_incookie/login/loginIn a throwaway WordPress (
wordpress:latest, public default visibility) with a probe mu-plugin:is_front_page()is0oninitand1ontemplate_redirect, which confirms the server-side check could never fire.Referer: https://portal.bcc.no/and thewp_has_logged_incookie:200on both v1.2.19 and this branch, so there's no server-side change. The rendered script no longer containsdocument.referer../wp-login.phpstill returns302tohttps://login.bcc.no/authorize?...on both.php -lpasses on PHP 8.4.#236 (silent
prompt=nonesign-in on any page) is not part of this. If we build it, it could replace the referrer and cookie guesses.🤖 Generated with Claude Code