Skip to content

Make auto-login from BCC referrers work again - #238

Merged
cs1m0n merged 2 commits into
masterfrom
fix/auto-login-referrer
Nov 11, 2026
Merged

cs1m0n merged 2 commits into
masterfrom
fix/auto-login-referrer

Conversation

@cs1m0n

@cs1m0n cs1m0n commented Nov 11, 2026

Copy link
Copy Markdown
Member

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 the wp_has_logged_in cookie ("logged in before on this device") triggered auto-login. Visitors coming from portal.bcc.no, brunstad.org or a host starting with bcc were 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 on init, where is_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 to template_redirect, as Auto-login via referrer and server-side never triggers #237 suggests. Moving it would turn on behaviour we don't want:

    • It has no once-per-session guard, unlike the script's sessionStorage flag. Anyone with the 10-year wp_has_logged_in cookie would be sent to login.bcc.no on every front-page visit and could never see the public front page without logging in.
    • It matches bcc anywhere in the referrer's host, which is broader than the script's check.
    • It only runs when the page cache misses, so behaviour would vary between requests. The script runs from cached pages too, so it covers the same cases.

    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_referrers here or in a follow-up.

Testing

Ran the script from the rendered front page through a fake document, location and sessionStorage in node, against v1.2.19 and this branch. The site's host in the test is bcc-test.no:

Scenario v1.2.19 This branch
No referrer stays stays
From portal.bcc.no / www.brunstad.org / bcc.media TypeError → /login
From google.com TypeError stays
Link within bcc-test.no TypeError stays (→ /login with only the typo fixed)
wp_has_logged_in cookie → /login → /login
Second front-page view in the tab stays stays

In a throwaway WordPress (wordpress:latest, public default visibility) with a probe mu-plugin:

  • is_front_page() is 0 on init and 1 on template_redirect, which confirms the server-side check could never fire.
  • Front page with Referer: https://portal.bcc.no/ and the wp_has_logged_in cookie: 200 on both v1.2.19 and this branch, so there's no server-side change. The rendered script no longer contains document.referer..
  • /wp-login.php still returns 302 to https://login.bcc.no/authorize?... on both.
  • No PHP warnings in the page or the container log. php -l passes on PHP 8.4.

#236 (silent prompt=none sign-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

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>
@cs1m0n
cs1m0n requested a balanced review from Copilot November 11, 2026 12:12
@cs1m0n cs1m0n self-assigned this Nov 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.referrer typo 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

@cs1m0n
cs1m0n merged commit 8a647ec into master Nov 11, 2026
7 checks passed
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.

Auto-login via referrer and server-side never triggers

2 participants