fix(webui): treat ?token= URL param as the login password (#194)
abef797misread the request and seeded the value as a bearer session token (which the operator would have to dig out of localStorage). The intent is simpler: `?token=<你的WebUI登录密码>` — the value is the plain WebUI login password, so the link is trivially constructable from something the operator already knows. - Revert the client-constructor bearer seeding fromabef797. - AuthBoundary: when no stored token already authed us and the URL carries ?token=, run it through client.login() (the normal password path). A correct password lands on the home page; a wrong one falls through to the login page (server-verified, no bypass). The password is carried into the forced change-password gate, matching the interactive login flow. - The param is consumed once and stripped from the URL (replaceState) before the login call — a password in the address bar leaks via history / logs / Referer. typecheck 12 包干净。
This commit is contained in:
2 files changed
+37
-28
No files matched your search
@@ -37,27 +37,6 @@ function extractErrorMessage(payload: ErrorPayload, fallback: string): string {
|
||||
return payload.message || payload.error || fallback;
|
||||
}
|
||||
|
||||
// #194: seed the bearer token from a `?token=…` URL query param so an operator
|
||||
// can bookmark / share a one-click auto-login link instead of typing the
|
||||
// password every visit. The token is consumed once and IMMEDIATELY stripped
|
||||
// from the URL (via replaceState) — a credential left in the address bar leaks
|
||||
// through browser history, server access logs, and the Referer header. It's
|
||||
// still validated server-side by the normal /api/status check, so a stale or
|
||||
// forged value just falls through to the login page.
|
||||
function consumeUrlToken(): string | null {
|
||||
if (typeof window === 'undefined') return null;
|
||||
try {
|
||||
const url = new URL(window.location.href);
|
||||
const token = url.searchParams.get('token');
|
||||
if (!token) return null;
|
||||
url.searchParams.delete('token');
|
||||
window.history.replaceState({}, '', `${url.pathname}${url.search}${url.hash}`);
|
||||
return token;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
class HttpApiClient implements ApiClient {
|
||||
private tokenStore: TokenStore;
|
||||
private currentToken: string | null;
|
||||
@@ -77,12 +56,7 @@ class HttpApiClient implements ApiClient {
|
||||
|
||||
constructor(opts: CreateApiClientOptions = {}) {
|
||||
this.tokenStore = opts.tokenStore ?? localStorageTokenStore(DEFAULT_TOKEN_KEY);
|
||||
// A `?token=…` link wins over any previously stored token, and is persisted
|
||||
// so a later reload (URL now stripped) stays signed in. Validation happens
|
||||
// in the normal status() gate, so an invalid link just shows the login page.
|
||||
const urlToken = consumeUrlToken();
|
||||
this.currentToken = urlToken ?? this.tokenStore.load();
|
||||
if (urlToken) this.tokenStore.save(urlToken);
|
||||
this.currentToken = this.tokenStore.load();
|
||||
this.onUnauthorized = opts.onUnauthorized;
|
||||
|
||||
this.processes = {
|
||||
|
||||
Reference in new issue
Block a user