Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/backend/token-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ interface TokenLogger {
error: (message: string, meta?: Record<string, unknown>) => void;
}

/** guacd sends the username as typed, so a DOMAIN\user login is split here. */
function splitDomainUser(username: string, domain: unknown) {
const slash = username.indexOf("\\");
return domain || slash < 1
? {}
: { domain: username.slice(0, slash), username: username.slice(slash + 1) };
}

export interface GuacamoleConnectionSettings {
type?: "rdp" | "vnc" | "telnet" | "rustdesk";
join?: string;
Expand Down Expand Up @@ -264,6 +272,7 @@ export class GuacamoleTokenService {
"ignore-cert": true,
...(!username && !password ? { "disable-auth": true } : {}),
...settingsOptions,
...splitDomainUser(username, settingsOptions.domain),
},
},
recording,
Expand Down
30 changes: 30 additions & 0 deletions tests/backend/token-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ describe("GuacamoleTokenService", () => {
expect(decrypted?.connection.settings["disable-auth"]).toBeUndefined();
});

it("splits a DOMAIN\\user login into the domain and the username", () => {
const split = tokenService.decryptToken(
tokenService.createRdpToken("windows.example.test", "CORP\\alice", "s"),
);
expect(split?.connection.settings).toMatchObject({
username: "alice",
domain: "CORP",
});

const kept = tokenService.decryptToken(
tokenService.createRdpToken("windows.example.test", "CORP\\alice", "s", {
domain: "OTHER",
}),
);
expect(kept?.connection.settings).toMatchObject({
username: "CORP\\alice",
domain: "OTHER",
});

const upn = tokenService.decryptToken(
tokenService.createRdpToken(
"windows.example.test",
"alice@corp.test",
"s",
),
);
expect(upn?.connection.settings.username).toBe("alice@corp.test");
expect(upn?.connection.settings.domain).toBeUndefined();
});

it("preserves recording metadata outside guacd connection settings", () => {
const recording = {
hostId: 42,
Expand Down