Skip to content

Build the GitHub button's URL in Go, not in four templates - #639

Merged
compscidr merged 1 commit into
mainfrom
fix/github-login-url-in-go
Sep 25, 2026
Merged

compscidr merged 1 commit into
mainfrom
fix/github-login-url-in-go

Conversation

@compscidr

Copy link
Copy Markdown
Collaborator

Follow-up to #638, prompted by a fair observation: it is odd that the themes carry this logic.

The leftover

#631 moved GitHub's authorize URL into Go so the escaping was decided once. It left each theme assembling the URL that reaches it:

<a id="github-button" href="/login/github{{ if .next }}{{ if ne .next "/" }}?next={{ .next | urlquery }}{{ end }}{{ end }}">

A nested conditional building a URL, copied into four repositories — the same shape of problem the earlier work set out to remove, one step further out.

The change

GithubLoginURL decides it, and the templates print the result:

<a id="github-button" href="{{ .github_login_url }}">

Beyond being shorter, this makes the URL's shape the server's business: if it ever needs another parameter, no theme changes again.

next stays in the context because the email login still redirects to it in the browser once its AJAX call succeeds — behaviour rather than URL construction.

Tests

  • TestGithubLoginURL — the empty and / cases give a bare path; & in next is escaped rather than starting a second parameter
  • TestGithubLoginURL_SurvivesARoundTrip — what the button points at parses back to the next it was built from, since GithubLogin reads it as a query parameter

Verified against a local instance

/login request rendered href
no next /login/github
?next=/admin/settings /login/github?next=%2Fadmin%2Fsettings
?next=https://evil.example /login/github (dropped by SafeNext)

Then followed it through: the button's URL redirects to GitHub with a state, and replaying GitHub's return with that state reaches the exchange — so the stored next and state still round-trip.

Themes

Merge order as before: this first, then the themes. An un-updated theme renders an empty href on the button, so unlike the last round they do want updating promptly — but nothing else on the page is affected.

🤖 Generated with Claude Code

#631 moved GitHub's authorize URL into Go so the escaping was decided
once. It left each theme assembling the URL that reaches it:

  href="/login/github{{ if .next }}{{ if ne .next "/" }}?next={{ .next | urlquery }}{{ end }}{{ end }}"

A nested conditional building a URL, copied into four repositories —
the same shape of problem, one step further out.

GithubLoginURL decides it instead, and the templates print the result:

  href="{{ .github_login_url }}"

Beyond being shorter, this makes the URL's shape the server's
business: adding to it later touches no theme.

next stays in the context because the email login still redirects to it
in the browser once its AJAX call succeeds; that is behaviour rather
than URL construction.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The change cleanly centralizes URL construction server-side, updates the affected template, and adds targeted tests that validate both escaping and round-trip behavior.

Review effort: Lite
Findings: None

What changed in this PR

Moves construction of the /login/github button URL out of theme markup and into Go so URL shape/escaping is defined once server-side, with coverage to ensure next is correctly preserved and safely encoded.

Changes:

  • Add GithubLoginURL(next) helper to build /login/github (optionally with ?next=...) using consistent escaping rules.
  • Pass github_login_url into the login template context and simplify the template to render it directly.
  • Add unit tests covering empty// cases, escaping (including &), and round-trip parsing of next.
File Description
themes/​default/​templates/​login.html Replaces inline conditional URL-building with {{ .github_login_url }}.
blog/​blog.go Introduces GithubLoginURL, computes next once, and injects github_login_url into the render context.
blog/​github_login_test.go Adds tests to validate escaping behavior and round-trip parsing for the constructed login URL.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@compscidr
compscidr merged commit 817a9bd into main Sep 25, 2026
3 of 4 checks passed
@compscidr
compscidr deleted the fix/github-login-url-in-go branch September 25, 2026 21:19
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.

2 participants