Skip to content

GitHub OAuth redirect_uri is built from window.location without encoding #631

Description

@compscidr

Surfaced by review on #629, but pre-existing and unrelated to that change, so filing separately.

Problem

Every theme's login.html builds the authorize URL like this:

"https://github.com/login/oauth/authorize?client_id=" + clientID + "&redirect_uri=" + window.location

window.location is concatenated raw. When the login page carries query parameters — and it does, /login?next=/admin/settings is the normal path since #623 — the result is:

...&redirect_uri=http://site/login?next=/admin/settings

Everything after the first unescaped & in the redirect URI would be read by GitHub as a further authorize parameter. A next value containing & mangles the URL outright, and redirect_uri is supposed to match the registered callback anyway, so the query string may fail GitHub's validation regardless.

Fix

Encode it, and probably strip the query rather than round-tripping it:

var redirect = location.origin + location.pathname;
... "&redirect_uri=" + encodeURIComponent(redirect)

next already survives separately — it is read from the query string on the way back in and validated server-side by SafeNext.

Affects

login.html in goblog's default theme and all three external themes, which each carry their own copy.

Testing note

This needs checking against a real GitHub OAuth app, including what the registered callback URL is set to, which is why it should not ride along in an unrelated PR.

Activity

  1. compscidr commented on Sep 25, 2026

    @compscidr
    CollaboratorAuthor

    Correcting this issue's proposed fix before it misleads anyone: stripping the query from redirect_uri would be a regression.

    The issue says "next already survives separately — it is read from the query string on the way back in and validated server-side by SafeNext." That is wrong about which query string. next round-trips through redirect_uri:

    1. visitor lands on /login?next=/admin/settings
    2. redirect_uri is that whole URL, query included
    3. GitHub returns them to it with &code= appended
    4. Login reads next from that query — it is only there because redirect_uri carried it

    So location.origin + location.pathname would have quietly sent everyone to / after signing in. The fix has to escape, not strip.

    Also worth recording: the token exchange in auth.requestAccessToken never sends redirect_uri, so this only affects the authorize step.

    Fixed in #636, which moves the URL construction into Go behind /login/github rather than escaping it separately in each of the four themes.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions