Skip to content
Open
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
11 changes: 8 additions & 3 deletions src/infra/device-pairing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { randomUUID } from "node:crypto";
import { randomBytes, randomUUID } from "node:crypto";
import fs from "node:fs/promises";
import path from "node:path";
import { resolveStateDir } from "../config/paths.js";
Expand Down Expand Up @@ -231,8 +231,13 @@ function scopesAllow(requested: string[], allowed: string[]): boolean {
return requested.every((scope) => allowedSet.has(scope));
}

function newToken() {
return randomUUID().replaceAll("-", "");
/**
* Generates a cryptographically secure token for device authentication.
* Uses 32 bytes (256 bits) of entropy from crypto.randomBytes(),
* encoded as base64url (URL-safe, no padding).
*/
function newToken(): string {
return randomBytes(32).toString("base64url");
}

export async function listDevicePairing(baseDir?: string): Promise<DevicePairingList> {
Expand Down
11 changes: 8 additions & 3 deletions src/infra/node-pairing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { randomUUID } from "node:crypto";
import { randomBytes, randomUUID } from "node:crypto";
import fs from "node:fs/promises";
import path from "node:path";
import { resolveStateDir } from "../config/paths.js";
Expand Down Expand Up @@ -143,8 +143,13 @@ function normalizeNodeId(nodeId: string) {
return nodeId.trim();
}

function newToken() {
return randomUUID().replaceAll("-", "");
/**
* Generates a cryptographically secure token for node authentication.
* Uses 32 bytes (256 bits) of entropy from crypto.randomBytes(),
* encoded as base64url (URL-safe, no padding).
*/
function newToken(): string {
return randomBytes(32).toString("base64url");
}

export async function listNodePairing(baseDir?: string): Promise<NodePairingList> {
Expand Down