Keep step-up elevation for the signed-in session and stop gating terminals
The proxy forwards an HMAC-derived session id (X-Pipelines-Session) on /connect and POST /files; the server trusts it only on token-authenticated requests and keys elevation by it, so reconnects stay elevated up to a 24 h cap. Terminals rely on their su -l login. The app no longer forgets the elevation on disconnect and asks again only on a fresh refusal.
This commit is contained in:
@@ -214,6 +214,21 @@ export class AuthStore {
|
||||
return { id, expires: Number(expires), issued: Number(issued) };
|
||||
}
|
||||
|
||||
/**
|
||||
* The opaque id the Pipelines server keys step-up elevation by, for a valid
|
||||
* token, else "". It is an HMAC (under the cookie secret) of the token's
|
||||
* generation and id, never the cookie: a new sign-in, a password change or
|
||||
* a revoke-all yields a new id, so the old elevation is never named again.
|
||||
*/
|
||||
sessionId(token) {
|
||||
const session = this.check(token);
|
||||
if (!session) return "";
|
||||
const { generation } = this.load();
|
||||
return createHmac("sha256", this.load().secret)
|
||||
.update(`pipelines-elevation-session.v1.${generation}.${this.notBefore}.${session.id}`)
|
||||
.digest("base64url");
|
||||
}
|
||||
|
||||
/** Signs one token out (server-side logout). */
|
||||
revoke(token) {
|
||||
const session = this.check(token);
|
||||
|
||||
+12
-5
@@ -8,6 +8,8 @@ import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
export const SERVER_TOKEN_HEADER = "x-pipelines-token";
|
||||
// The proxy's opaque id of the signed-in web session (protocol.SessionHeader).
|
||||
export const SESSION_HEADER = "x-pipelines-session";
|
||||
|
||||
export function serverTokenPath(env = process.env) {
|
||||
if (env.PIPELINES_SERVER_TOKEN_FILE) return env.PIPELINES_SERVER_TOKEN_FILE;
|
||||
@@ -37,12 +39,17 @@ export function serverToken(path = serverTokenPath()) {
|
||||
return cached.token;
|
||||
}
|
||||
|
||||
// Headers for the local upstream: any client-supplied token is dropped and the
|
||||
// proxy's own is set, so the browser never chooses what the server sees.
|
||||
export function withServerToken(headers, token = serverToken()) {
|
||||
// Headers for the local upstream: any client-supplied token or session id is
|
||||
// dropped and the proxy's own token is set, so the browser never chooses what
|
||||
// the server sees. session, when given, is the proxy's derived session id
|
||||
// (AuthStore.sessionId), set only where the server keys elevation by it.
|
||||
export function withServerToken(headers, token = serverToken(), session = "") {
|
||||
const result = { ...headers };
|
||||
for (const name of Object.keys(result))
|
||||
if (name.toLowerCase() === SERVER_TOKEN_HEADER) delete result[name];
|
||||
for (const name of Object.keys(result)) {
|
||||
const lower = name.toLowerCase();
|
||||
if (lower === SERVER_TOKEN_HEADER || lower === SESSION_HEADER) delete result[name];
|
||||
}
|
||||
if (token) result[SERVER_TOKEN_HEADER] = token;
|
||||
if (token && session) result[SESSION_HEADER] = session;
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user